Add controller option removed after upgrading MVC4

2019-07-04 06:19发布

问题:

This question already has an answer here:

  • How do I get the “Add Controller” and “Add View” menu options in my ASP.NET MVC 5 project? 2 answers

I have started a new basic Razor website, as a sort of 'clean slate' for the update.

I followed the tutorial that everyone recommends, and it had completed without an issue.

Unfortunately, now, I have no option to add a controller.
When I right click on the Controllers folder and move to add, there is no Controller option. There is also no Controller option in add>new item or add>from template.

Can anyone please help me get this functionality back? I've been browsing for solutions for a while now, and mine seems pretty unique.

回答1:

Install the following items:

  1. Visual Studio 2012 Update 4
  2. Web Tools 2013.1 for Visual Studio 2012 (Web Platform Installer | Direct Download)

Then follow this tutorial to upgrade your MVC 4 project to MVC 5.

Finally make sure your project has the following ProjectTypeGuids:

 <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

In MVC5 the option you're looking for might be hidden under the Add Scaffold menu option. See the release blog post for more information on MVC5 scaffolding.