I can't add razor view to MVC 5 project in Visual Studio 2017.
There just doesn't seem to be the template
As you can see if I choose Web from template list nothing is visible and all I see is Please choose a project type.
Now this is puzzling as I've seen this related SO post & this where both of them suggest to set project type GUID in .csproj.
I do have it set and it was there (I didn't add anything)
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
Looking at the list of GUIDs it seems that the first GUID suggests that this is ASP.NET MVC 5 project.
I also checked VS2017 installation and I do have web tooling installed
Any clue what I can also try to enable adding web templates to project?
Are you trying to add a new project to a solution or a new item to a project? Its not clear in your question?
Within your project (Solution Explorer), try right click on the Views Folder, choose add, New Item and see if you can find anything there?
Related
One of my project build in MVC5 where I need to modify in view, but in this project I could not able to add view by right click option ( both from view folder as well as from particular controller). I copied another existing view and rename it as per my requirement, but in that view Intelsence is not working.
Can anyone suggest me any patch up missing anywhere?
Thanks in advance..
You have to modify your vs2012 asp.net-mvc-5-vs2012
Visual Studio 2012 update 4
Web Tools 2013.1
Just wondering where they may have moved the tooling to right click on an action method and add a view. I get no menu option.
Right now (ASP.Net 5/Core 1.0 RC1), that tooling does not exist.
There are plenty of places where the tooling is not there yet. For example, in the 'Web API' project template you cannot use scaffolding or add authentication during project creation via Visual Studio.
The 'web application' project template is the most complete but still has holes.
What I normally do is just copy one of the other views (About.cshtml for example) and edit the places I need to edit, you'll get to the same result.
Thanks
I've got an MVC project, and I want to add Identity to it, but I can't seem to find any good articles on how to do so.
Is there an easy way to add Identity to an existing project?
I already have a database with stuff in it
Well, in one respect, you simply have to add the Nuget package and start writing code with it, but I think you're probably talking about all the extras: the pre-written code and samples for doing things like password resets, two-factor auth, etc.
For that, no, there's not really an easy way, at least in the sense of click a button and go. What I would recommend is creating a new MVC 5 project with Individual Auth, and then adding the Identity Samples Nuget package to it. Then, open your existing project in another Visual Studio window and copy/paste or use the sample code as a guide for writing your own.
Here's a tutorial that I followed for adding ASP.Net Identity to an existing project. It's up to date and from a reputed source at the asp.net/identity site.
I will echo what Chris said. there is no "easy way" . here is a video link featuring Scott Allen (a pioneer in web dev (Video link)
You can check his other videos as well
I think the easiest way to do that is to do the following steps:
Install All Identity Packages from nugets to your existing MVC project.
Create New MVC Project and choose Authentication type: Individual Authentication.
Copy IdentityModels.cs and all related files including (controllers, views and IdentityConfig) from New project to an existing MVC project.
Add migration to create required tables on database.
I'm getting back there because I ran into this situation some time back and applied solutions from here.
In the meantime I found something simpler.
VS has you covered to actually scaffold the files.
Right-click the project ► Add ► New Scaffolded Item...
Then in the new dialog, select Identity and click Add.
On the next screen you'll be given a list of items to check. You don't need to but you can import all of them if you want. It will ask for the data context but there's not in my case. In yours it should be already filled.
Click Add, you're done.
ASP.NET MVC provides the ability to select a 'Scaffold template' upon which a newly-created view will be based (Add View > Create a strongly-typed view > Scaffold template).
Is it possible to create your own Scaffold Template? And if so, how?
ASP.NET MVC uses T4 templates. Here's an overview.
Here are the steps:
In the Package Manager Console type: install-package mvc3codetemplatescsharp
Accept all the warnings
The CodeTemplates folder will be added to your project containing the templates
From here you could either modify the existing templates or add new one.
Or if you want to modify those globally you could to this in the C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 3\CodeTemplates\ folder.
You can use T4 without nuget of course: Place a folder in the root of the application website (the project containing the views). The directory structure is important so it should be
\CodeTemplates\AddView\AspxCsharp\MyTemplate.tt
You can copy the contents from one of the existing templates located in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 3\CodeTemplates\
Next, clear the property on the TT file named "Custom Tool". This should be blank.
Then right-click on any Controller Action and say "Add View" or since the controllers are in a separate project in our case, right click on the View folder and click "Add View".
From the dropdown Click "Create a strongly typed View" and then enter the type to use under "View Data Class:"
Finally, in the "View Content" dropdown, select "MyTempate". This should show up if you've entered the folders correctly.
In Visual Studio 2012 with MVC 4, the easy way (install Nuget package) gets you an incomplete setup, because the Nuget package is woefully out of date (last updated in 2011 - perhaps the day it was created).
You have to use the equivalent of Francis Shanahan's answer, but instead the path to copy things from is (64-bit):
C:\Program Files (x86)\Microsoft Visual Studio\11.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 4\CodeTemplates
You:
Add a Reference to Microsoft.Web.Infrastructure, which you can find in Assemblies > Extensions.
Copy this CodeTemplates folder (including the folder itself) to the root of your Project and Include it in the Project
Ignore the compiler errors for now (like can't find MvcTextTemplateHost)
Go through the Properties of each of the added files and delete the text in the "Custom Tool" property of each. When you do the expand arrow next to each file will disappear (because the file will no longer be generated in-place)
Save All and build - compiler errors gone
If the compiler errors don't go away - especially if you're seeing an error in a generated .cs file Visual Studio can't find, and a .tt file - close Visual Studio, wipe your temp folder, and reopen the solution. In one case I went so far as restarting before the issue cleared up. It was caused by a generated .cs file from a .tt template that Visual Studio was still trying to automatically generate code for.
In addition, the names of the .tt files are a little bit confusing - here's how they map:
GUI:
Empty MVC controller
MVC controller with read/write actions and views, using Entity Framework
MVC controller with empty read/write actions
Empty API controller
API controller with read/write actions, using Entity Framework
API controller with empty read/write actions
CodeTemplates\AddController's files map respectively:
Controller.tt
ControllerWithContext.tt
Controller.tt
ApiController.tt
ApiControllerWithContext.tt
ApiController.tt
There's an if statement in Controller.tt and ApiController.tt that handles the with/without read/write actions functionality.
For the views, naming is intuitive except that List.tt creates Index.cshtml, and Empty.tt is used for any View besides Create/Delete/Details/Edit/Index.
This question covers what properties you can use in the .tt templates.
.tt templates are Microsoft T4 templates. T4 Template Syntax.
Or, for Visual Web Developer Express on a 32-bit system, another location for these files is C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\VWDExpress\ItemTemplates\CSharp\Web\MVC 3\CodeTemplates
This MSDN article discusses Scaffolding and Page Templates:
http://msdn.microsoft.com/en-us/library/cc488540.aspx
Which, in turn, links to the following article for modifying the templates:
http://msdn.microsoft.com/en-us/library/cc488537.aspx
In an existing VS2008 SP1 web project I'm introducing an MVC page. I was able to manually create a view and get it working just fine but I'm unable to get the "Add View" and "Add Controller" to work from the Solutions Explorer. Also, the MVC templates don't show up when I try and Add a New Item.
I know my VS2008 is setup properly because on a new project everything works fine (MVC templates show up in Web Items) and the "Add View" and "Add Controller" work fine as well. Is there a trick to get my legacy project to see these options.
I tried look around the csproj files. Nothing obvious there.
I see the template zip files in my folder ...Common7\IDE\ItemTemplates\CSharp\Web\MVC
Thanks.
My guess is that the project type is probably set wrong. I know it did change after one of the betas.
Try this: First, check in your existing files to source control, in case you accidentally mess up the project file. Open both of the *.csproj files (the one that "works" and the one that "doesn't") as text. You will have to unload the projects in the IDE in order to do this. Copy the <ProjectTypeGuids> value from the one that "works" to the one that "doesn't". Now reload the projects. See if that fixes the problem.