Context menu to Add Controller/View missing

2019-01-06 10:53发布

问题:

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?

回答1:

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.



回答2:

Step to change the GUID

  1. Right click on the project in solution explorer
  2. Click unload project
  3. Right click again on the project in solution explorer
  4. Edit projectfolder/projectname.csproj
  5. Chagne GUID
  6. Right click and select "Reload Project"

In <ProjectTypeGuids> tag add any of these GUIDs in beginning

{E3E379DF-F4C6-4180-9B81-6769533ABE47};

{E53F8FEA-EAE0-44A6-8774-FFD645390401};


回答3:

For people using MVC 5, add this key

{E3E379DF-F4C6-4180-9B81-6769533ABE47}; 

in the beginning of . The other guids won't work.



回答4:

Do nothing just update your MVC project. Fire this command in your Nuget Package Manager console.

Update-Package Microsoft.AspNet.Mvc



回答5:

Answer 2 was correct just wrong guid

{E53F8FEA-EAE0-44A6-8774-FFD645390401}

is what you need for MVC in VS2010



回答6:

By right clicking the project in Solution Explorer, you need to unload the project, edit the project, change the tag using the chart below, and then reload the project. Paste the appropriate GUID to the front of the list in the csproj file.

The different GUIDs for different versions of MVC:

ASP.NET MVC 1   {603C0E0B-DB56-11DC-BE95-000D561079B0}
ASP.NET MVC 2   {F85E285D-A4E0-4152-9332-AB1D724D3325}
ASP.NET MVC 3   {E53F8FEA-EAE0-44A6-8774-FFD645390401}
ASP.NET MVC 4   {E3E379DF-F4C6-4180-9B81-6769533ABE47}
ASP.NET MVC 5   {349C5851-65DF-11DA-9384-00065B846F21}


回答7:

I had the same problem when opened MVC project as Web Site. I reopened solution thru Open -> Project and this functionality worked as I expected.



回答8:

I know this is an old post, but I just ran into this switching between VS2013 and VS2012 for an MVC 5 Project. The issue I had is that the version of the MVC Template I was using wasn't installed from the Visual Studio update. VS2012 didn't come with MVC5 as it came out after it, so an update was required for VS2012 to add the template. Same with VS2010 and MVC4 I imagine.

Anyhow, downloading the update from Microsoft resolved my issue as when another version opened and saved the project, it would again disappear when using the fix above.

Here is the link to the VS2012 MVC5 update. Ensure that you download and install both the Tools update and the VS plugin.

http://www.microsoft.com/en-us/download/details.aspx?id=41532



回答9:

For me it was missing from where I expected it to exist (at the top of the menu which shows when you right click on a view folder and click on 'Add'), but then I found it at a sub context menu under 'New From Template'! I have re-sharper installed, I guess it happened because of it (Also Visual Studio 2012):



回答10:

Had the same problem with VS2015, helped changing ProjectTypeGuids content to:

{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}


回答11:

I am on VS2012 and tried Dimitrov's answer (adding a particular GUID to the project file's ProjectTypeGuids). While this did give me the missing context menu for the controller actions, I was missing intellisense on my Razor pages.

It turns out I was missing the VS tooling for the version of the MVC project I was working on, and installing this tooling (rather than editing the project file) resolved my issues.

Download page for ASP.NET and Web Tools 2013.1 for Visual Studio 2012

I found this download link from the following blog post:

Announcing release of ASP.NET and Web Tools 2013.1 for Visual Studio 2012



回答12:

You are correct. The presence of these context menu options is project type/template specific.



回答13:

For older version

{F85E285D-A4E0-4152-9332-AB1D724D3325}


回答14:

When all else fails (before reinstalling VS2015) you might want to reset VS cache. This worked for me (after repairing - NOT meddling with GUIDS). Just delete the contents in the folders mentioned in this link (takes about 30 seconds), then execute the command. That takes another 10 seconds. Restart VS and you will see the screens of a first-time user in VS. It worked like a charm.

http://blogs.msdn.com/b/willy-peter_schaub/archive/2010/09/15/if-you-have-problems-with-tfs-or-visual-studio-flush-the-user-cache-or-not.aspx



回答15:

This problem can also occur when you have just checked out a fresh copy of your solution from your code repository and the NuGet packages, including Microsoft.AspNet.Mvc, have not yet been downloaded. Rebuilding the solution fixes the problem.



回答16:

VS2012 Context menu to Add Controller/View missing

In VS2012 & MVC4 try unistall Web API 5.2 in PM:

UnInstall-Package Microsoft.AspNet.WebApi