Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Context menu to Add Controller/View missing

I have integrated ASP.NET MVC 4 into existing asp.net web site. Both works fine but I don't see any menu/shortcuts to create controller/view within visual studio IDE. Are those only available to ASP.NET MVC template?

like image 328
user1186065 Avatar asked May 10 '12 18:05

user1186065


People also ask

How do you add a view to a controller?

Open the “HomeController” >> Set cursor inside the Action Method >> Right click on inside the action method >> click on [Add View] as follow. Provide the view name and select the appropriate layout and click on the “Add” button as follows.

How do I add a new controller code in Visual Studio?

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.

How do you go from view to controller?

You can right click on the Index Method of the controller and you will see an option "Go To View" which will do exactly that.

How do I add a view in Visual Studio 2012?

In the project, add a view template that you can use with the Index method. To do this, right-click inside the Index method and click Add View. The Add View dialog box appears.


1 Answers

Are those only available to ASP.NET MVC template?

Yes, but you could cheat. The way Visual Studio shows those shortcuts is by looking at the project type and if it sees that it is an ASP.NET MVC project it will make them available. But how does it know it is an ASP.NET MVC project? After all ASP.NET MVC is an ASP.NET project.

Open the .csproj file and look for the <ProjectTypeGuids> node of your ASP.NET MVC 4 project. You will see something like this:

<ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids> 

Now open the .csproj file of your regular ASP.NET project and simply add the {E3E379DF-F4C6-4180-9B81-6769533ABE47} GUID as first item in the list (if you don't project does not even load). That's all. Now you will see the ASP.NET MVC specific context menus in your WebForms project.

like image 136
Darin Dimitrov Avatar answered Oct 08 '22 01:10

Darin Dimitrov