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)
In Solution Explorer, right-click the Controllers folder and then select Add Controller. Name your new controller "HelloWorldController". Leave the default template as Empty controller and click Add.
The easiest way to create a new controller is to right-click the Controllers folder in the Visual Studio Solution Explorer window and select the Add, Controller menu option (see Figure 1). Selecting this menu option opens the Add Controller dialog (see Figure 2).
In Solution Explorer, right-click the Controllers folder and then click Add, then Controller. In the Add Scaffold dialog box, click MVC 5 Controller - Empty, and then click Add. Name your new controller "HelloWorldController" and click Add.
To add a controller, in Visual Studio Code right-click the Controllers folder and select New File. When the text box appears, enter CarsController. cs as the new file name. This will add a new C# file that will also open in the code editor.
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:
Right Click on the "Controllers" folder in your MVC project
Add > Controller...
Choose a Controller Template. (I prefer MVC 5 Controller Empty)
Alternate Way:
Right Click on the "Controllers" folder in your MVC project
Add > New Scaffolded Item...
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:
??? 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With