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?
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
When I create a new template (.cshtml) in the Views folder of my Visual Studio solution it is not showing up in the backoffice.
If I create a template from the backoffice a file is created in the Views folder that I then have to add to VS as a exciting file - why don't the backoffice show the template if I create one from Visual Studio? I've tried rebuilding the project.
You can do it in 2 ways:
Create your views in umbraco backend. Then go to visual studio and click the "Show All Files" button in solution explore. Find your new views in the Views folder. Right click on each file and choose "Add file to project".
Create your views in visual studio as normal. Then go to umbraco backend and create your Templates, and give them the same name as the view in visual studio. (If your template name in umbraco is "Text Page", -your file name should be "TextPage")
As ProNation says, all templates needs a db reference.
Views/templates work differently to some of the other files like scripts and CSS because they require a reference in the database to allow you to associate them with your doctypes.
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.