I installed Umbraco 8.4 as per the instructions found at https://our.umbraco.com/documentation/Getting-Started/Setup/Install/install-umbraco-with-nuget
Once done within Visual Studio 2017 i tried to created a new Controller and the folder (Controllers) was missing.
I'm not sure if i've missed something but i didnt want to create the folder manually in case it introduces new problems later down the line.
I thought to recreate the project but instead of selecting Empty as the project to use MVC but after reading through a few threads it seems the correct way is to select an empty project.
Under the bin directory i do see System.Web.Mvc.dll
Am i missing something?
You should definitely not use the MVC project template when creating a new project - that will add all sorts of dependencies that will likely conflict with what comes with the Umbraco NuGet package.
Go with the "Empty" template and then add in the NuGet and it will give you the dependencies you need for Umbraco to run. If you need to add in other stuff from MVC afterwards, you can add these in a version that aligns with what the Umbraco package has added.
In regards to the Controllers folder - it really doesn't matter where this folder lives or what it is called. Controllers are registered by other means. You are totally fine to create this folder manually and call it whatever you prefer.
I think most people actually prefer to keep Controllers in a completely separate project in the VS solution. Then reference that project by your main project to ensure the compiled DLL is included in your web project - and thereby your controllers can be used by the Umbraco website itself. By doing this, you get a clean separation of your .cs source files so you won't accidentally be deploying those when you deploy your site. To do this you would of course require to add UmbracoCms.Core NuGet package to your other project in order to use Umbraco functionality.
Keep in mind if you are adding plain MVC controllers (not inheriting from the Umbraco base controllers - and therefore not getting automatically registered) you will need to manually register these controllers in the route table in order to access them.
This is no different from what you would do in a normal ASP.NET MVC project, but since this isn't added by default in an Umbraco project - you need to do it yourself.
See this answer for instructions on how to do it: https://stackoverflow.com/a/56972929/336105
Related
I'm currently trying to learn and understand all the new Identity bits and pieces with .Net Core 2.1/MVC. Previously, I have used MVC3 MVC Identity and it was straight forward - it automatically created the Model, View and Controllers and I could easily edit everything and anything.
With .Net Core, it seems to automatically inherit everything from the framework and I just don't easily understand how to override.
I've followed the guides located here, and have managed to scaffold all the pages (e.g. create user, reset password, login), however, this does not create any of the models or controllers.
Because of this, I now have a project with all the pages, but, it fails to build with all the models missing:
CS0246 The type or namespace name 'ChangePasswordModel' could not be found (are you missing a using directive or an assembly reference?
I feel like I am missing something obvious and I can't believe that I am struggling so much on something that ~10 years ago was simple.
How can I create/import the missing Controllers and models?
Identity comes with a default UI composed of Razor Pages and static files housed in a Razor Class Library. It's added by default when you either use AddDefaultIdentity to enable Identity in your project or explicitly call AddDefaultUI on any of the other Identity bootstrapping extensions methods (AddIdentity/AddIdentityCore).
Views and static files in Razor Class Libraries are embedded resources, and as such are treated as if they physically existed directly in the apps that reference them. However, anything that actually does physically exist in your app will be used before any embedded resources. As such, you can override anything coming from an RCL, simply by creating the same file in the same location as it exists in the RCL in your app. The Identity scaffold simply copies over the selected Razor Pages into your project such that they will override in this way.
Since Razor Pages are used for the default UI, there's no controllers or separate model classes. The models used for the views are established in the Razor Page codebehinds, so for each page you scaffold in, you should have both Page.cshtml and Page.cshtml.cs files added.
If your build is failing after doing the scaffold, the build is not seeing the *.cshtml.cs files (codebehinds). Verify that they do exist in your project's file structure. If they don't, there's some fundamental problem with the scaffold in your instance of Visual Studio, which will likely require reinstalling or at least repairing Visual Studio.
Assuming they are there, then there's something stuck in the build process. Occasionally files do get locked and Visual Studio will complain that it's missing references, when in fact it's simply missing the very assemblies those come from. In such cases, you can navigate into your project directly and remove the bin and obj directories completely. Then, come back into Visual Studio and do a rebuild. If you have more than one project, you should rebuild your entire solution, as it could be a project reference that's actually failing to build.
I had a solution that included both an ASP.NET MVC web project and a WebAPI project. The solution was created originally with VS2012, but I recently upgraded it to VS2013.
I just noticed when going to add a controller that I'm not getting the correct options in the right click menu. For instance if I go to the web project and right click the controllers folder, the option to add a controller isn't there. Instead I have add WebAPI controller. It's exactly the opposite for the WebAPI project.
Things seem to build and run ok so far, but it's going to be a pain manually adding things and I'm wondering if something else might break. Any idea why this is happening or how to fix it?
I would guess that project type is different in your csproj. Take a look at this question:
What is the significance of ProjectTypeGuids tag in the visual studio project file
Here is what I have on my machine for c# asp.net mvc project:
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
Take a look at your guids and see what they mean.
You could see the meaning of the different GUID in the register :
•HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\Projects for
ProjectTypeGuids
•HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\Packages for
packages reference by some project
Using Visual Studio 2013, create a new ASP.NET Web Application project using the MVC template. Verify that the Add View dialog functions by right-clicking the "Views\Home" folder and choosing "Add... View".
Now add a new F# Library project to the solution. The Add View dialog should still function correctly.
Now add a project reference from the MVC project to the F# project by right-clicking the References folder, choosing Add Reference, Then browse to Solution...Projects on the left and checking the F# library project that you just added.
At this point, if you right-click the "Views\Home" folder and choose "Add... View" you will get an error in a pop-up alert box instead of the Add View dialog:
There was an error running the selected code generator: 'Object reference not set to an instance of an object.'
Workarounds include, but are hopefully not limited to:
Remove all your references to any F# projects every time you want to add a new view.
Unload any referenced F# projects, but leave the project references in place, every time you want to add a new view.
My questions are:
Are other people seeing this behavior, or is it just me?
Does anyone know of a better work-around than removing references or unloading F# projects?
Does anyone know if Microsoft is already working on fixing this? If not should this be reported to the F# team or the Visual Studio team?
Between this issue and the fact that it is still impossible to use NuGet to add an Entity Framework 6 reference to any F# project, I'm starting to get nervous about Microsoft's level of commitment to the F# language.
Not sure if this will help you but check the version of EntityFramework in your solution. I had two projects within my solution and for whatever reason, the web project had EF 6 and the class library project was EF 6.1. Once I uninstalled EF completely from the solution and reinstalled EF 6.1 on both project, the "Add new view" action started working.
I received the same error message when adding views or controllers in a C# & MVC multi-project solution, using EF 6.1 and VS2013 with Update 3. The problem was because the nuget "packages" folder was marked as read only, because it was checked into source control. I checked the entire folder out, making it editable, and it started working fine, allowing me to scaffold straight from VS.
I also received the error message in a web.api project because I forgot to add the Entity Framework connection string to the web.config (it was using Areas and EF was looking in the Area web.config, not the web.config in the root).
I am looking for making some MVC Controller and Models so add my desired functionality to my website, but How can I add a controller while the project can't even build, because there are lots of compilation errors in umbraco internal pages (e.g. in Umbraco/ and UmbracoClient/ folders).
How would I overcome these problems and make my own controllers - models? don't they need a compilation?
Without seeing your compilation errors I can't be sure, but unless your version of Umbraco is seriously corrupt the most likely cause is because there is a problem with references - either to packages in the packages folder (which Umbraco 6.x.x builds create) or to another folder (references?) that someone may have added if you are using mvc bridge and Umbraco 4.x.x.
Assuming this is a 6.x.x build then are the errors connected with missing assemblies? Are the permissions on the folders (like packages) in your solution allowing access? Is the packages folder missing?
You could create a new blank Umbraco instance and migrate your work so far if your Umbraco install is corrupt.
I have an ASP.NET MVC 2 web site that I've already upgraded to MVC 3. I'm not finding it very easy for new Razor views to coexist with my older ASPX views. I've found some articles, but I've failed at all of their suggestions and it seems not many people have been successful at doing this.
Has Microsoft made anything to make it easier to add Razor support to an upgraded MVC 2 app?
I haven't done this myself, however in this post by Scott Guthrie, there's this screenshot:
Given that this setting exists on the View, it suggests that you can have multiple views using different view engines. This means you should be able to run your existing code as normal, but add new views using Razor.
You can always test this out with a new project, and try adding two views - one using ASPX and one using Razor. If it all works, try diffing the test project to your existing one (specifically things like project and .config files).
You can use this tool from Telerik: https://github.com/telerik/razor-converter to convert your ASPX to CSHTML
The following steps worked for me.
Create another Temporary project based on MVC 3 Razor support by default
Compare the references, web.config (main one and one under views folder) in the Temporary project with my own project. Here I found references to System.Web.Helpers & System.Web.Webpages. Similar mentions exist in the web.config files also. Just copy those sections from the temporary project to your project.
Copy the _ViewStart.cshtml file from temporary project to your project (under Views folder)
Copy the _Layout.cshtml file from temporary project to your project (under Views\Shared folder)
Also check inside _Layout.cshtml. It may be referencing other partial views, jquery (js file) etc. Make sure they all exist in your own project.
That's it. Compile and all should be set right.