In Visual Studio 2013 / ASP.NET MVC 5, How do I add a new Controller?

前端 未结 4 867
孤独总比滥情好
孤独总比滥情好 2020-12-31 07:51

In ASP.NET MVC5 + VS 2013 (preview at time of writing), how do I add a new Controller?

In past versions (VS 2012 / MVC 4), I was able to right click on the Controll

相关标签:
4条回答
  • 2020-12-31 08:16

    Updated this answer on Nov 14 2013, after the official VS2013 release to reflect changes in the final release -ds

    For Visual Studio 2013 (Released Version)

    Note: The final release brought back the "Add Controller" context menu.

    Easy Way:

    1. Right Click on the "Controllers" folder in your MVC project

    2. Add > Controller...

    3. Choose a Controller Template. (I prefer MVC 5 Controller Empty)

    Alternate Way:

    1. Right Click on the "Controllers" folder in your MVC project

    2. Add > New Scaffolded Item...

    3. Choose a Controller Template

    This method also displays non-controller templates such as views, areas, and more WebAPI features making the list longer.

    For Visual Studio 2013 (Preview and Release Candidate)

    Note: VS 2013 Preview and RC did not include the "Add Controller" context menu.

    To create a new controller with Visual Studio 2013 + ASP.NET MVC 5:

    1. Right click on the Controllers folder.
    2. Click Add > Scaffold...
    3. Choose one of the "MVC 5 Controller - ???" types.

    ??? can be "Empty" meaning Controller class only with no pre-built views... all the way to "MVC 5 Controller with read/write actions and views, using Entity Framework" which produces a Controller class with multiple methods and associated View .cshtml files.

    In prior versions of Visual Studio + MVC, "Add Controller" initiated a configurable scaffold wizard. The preview versions of 2013 instead displays a list of pre-built scaffolding templates.

    0 讨论(0)
  • 2020-12-31 08:19

    Additional Options for Visual Studio 2013 (release version, ultimate).

    Dan Sorensen's answer should be your first port of call (it was for me). However, if this does not fix it, your only solution is to reinstall.

    I first uninstalled all Extensions and any other tooling (e.g. Azure SDK 2.2), then uninstalled VS 2013.

    After a restart, I reinstalled VS2013, and then extensions. After this the controller menus reappeared.

    0 讨论(0)
  • 2020-12-31 08:25

    follow these two steps

    1)Update your Visual studio 2013

    2) unload your project from solution explorer then Reload it again.

    0 讨论(0)
  • 2020-12-31 08:26

    While working on a new project, I noticed that the Controller option was present until I added the System.Web.Mvc reference. Removing the System.Web.Mvc reference restored the option to add an MVC 5 Controller.
    EDIT: Adding the new Controller automatically added the System.Web.Mvc reference again.

    0 讨论(0)
提交回复
热议问题