Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2013 button to add a View is disabled

After creating a few views, the AddView>Add button became disabled and I can't add views anymore. Does anyone have a hint about that?

enter image description here

EDIT

I can add views using the Add New Item command and selecting Views, but it's nonsense to me.

like image 678
Leandro De Mello Fagundes Avatar asked May 02 '14 19:05

Leandro De Mello Fagundes


People also ask

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.

How do I create a view in Visual Studio?

Right click the Views\HelloWorld folder and click Add, then click MVC 5 View Page with Layout (Razor). In the Specify Name for Item dialog box, enter Index, and then click OK. In the Select a Layout Page dialog, accept the default _Layout.

How do I add Razor view?

Right-click on the Views/HelloWorld folder, and then Add > New Item. In the Add New Item - MvcMovie dialog: In the search box in the upper-right, enter view. Select Razor View - Empty.


1 Answers

You may well have solved this by now, but I thought I'd add my answer for others suffering with this issue.

This same issue happened to me, and the solution was to edit the .csproj file to tell Visual Studio that it was an MVC project.

Here's what you do:

1) Open up the .csproj file of the MVC project in a text editor (Notepad is fine).

2) Find the tag .

3) For visual Studio 2013 it should read like this (may work for 2012 also):

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

4) Save the changes - Visual Studio will detect them and re-load the project.

Here's why you do it:

All that line in the .csproj file does is tells Visual Studio which type of project it is.

E3E379DF-F4C6-4180-9B81-6769533ABE47 = ASP.NET MVC 4.0

349c5851-65df-11da-9384-00065b846f21 = Web Application

fae04ec0-301f-11d3-bf4b-00c04f79efbc = C#

In your case, I expect E3E379DF-F4C6-4180-9B81-6769533ABE47 is missing, so VS doesn't know that it's an MVC project, therefore won't allow you to add Views and Controllers.

You can look up the various guids here in case you ever need them. http://www.codeproject.com/Reference/720512/List-of-Visual-Studio-Project-Type-GUIDs

I hope this is a help to you.

like image 176
Laurence Frost Avatar answered Oct 27 '22 10:10

Laurence Frost