13

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 Controllers folder and click "Add Controller". That option is no longer there. Where did it go?

(Side note: I am not certain if MVC 5 is where the change takes place or if it a change in the VS 2013 tooling as I updated both. I suspect it is with the new ASP.NET tooling for VS 2013)

Dan Sorensen
  • 11,403
  • 19
  • 67
  • 100
  • 4
    I asked because I have legitimately been looking for where the feature went since I upgraded last week. I finally found it and doc'd it here for you or my future self. "To be crystal clear, it is not merely OK to ask and answer your own question, it is explicitly encouraged." (source: http://blog.stackoverflow.com/2011/07/its-ok-to-ask-and-answer-your-own-questions/ ) – Dan Sorensen Jul 12 '13 at 22:06
  • It's not biggie, but changed my workflow & is different from most MVC documentation, so I figured I'd make a note of it. Cheers :-) – Dan Sorensen Jul 12 '13 at 22:35
  • 4
    stackoverflow encourages sharing knowledge in QA format. – Kunal Deo Jul 16 '13 at 08:57
  • 2
    FWIW, I'm seeing the same issue, but in my case, the scaffolding option only includes the ASP.Net Web API controllers, not the MVC ones. – Jim Wooley Sep 04 '13 at 18:23
  • What version of Visual Studio are you using? – Dan Sorensen Sep 30 '13 at 21:25

4 Answers4

23

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.

Dan Sorensen
  • 11,403
  • 19
  • 67
  • 100
  • 3
    Might have to down-vote this answer: I have VS2013 ultimate RTM with MVC5, and "Add Controller", "Add Scaffold" are not present. I'm not sure what's wrong, I've tried reinstalling web tools. – Quango Dec 12 '13 at 16:54
  • I also find that "Controller" isn't listed in the templates in "Add" dialog. This was .NET 4.5 fresh new project, MVC + WebAPI. Something is broken! – Quango Dec 12 '13 at 17:06
  • Quango: The menu changed between RTM and final release. My RTM answer was based on VS 2013 Professional RTM, not Ultimate. However, I would think they would be similar. Unfortunately, I do not have RTM installed any longer, so I cannot follow up on this answer. – Dan Sorensen Dec 12 '13 at 17:22
  • Dan: please ignore my griping. The menu options are the same: I eventually bit the bullet and did a full reinstall of VS2013 and all extensions. This has restored the menus. – Quango Dec 15 '13 at 22:08
1

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.

Quango
  • 12,338
  • 6
  • 48
  • 83
1

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.

Hive
  • 193
  • 1
  • 4
  • 17
0

follow these two steps

1)Update your Visual studio 2013

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

Umar Abbas
  • 4,041
  • 2
  • 23
  • 21