user1186065
user1186065

Reputation: 1877

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?

Upvotes: 58

Views: 71243

Answers (18)

sreeni vasan
sreeni vasan

Reputation: 1

You might have opened the project as folder type which limits the visual studio IDE to limit certain GUID options, so load your project solution.

It should work. Add view or Add controller should be available as soon as you right click on the ActionResult or inside controller.

Upvotes: 0

Alex from Jitbit
Alex from Jitbit

Reputation: 60712

Here's what worked for me with VS 2017.

First check if you're able to create a new empty MVC project.

If not - this means some components are missing. Launch Visual Studio Installer (typicall sits in C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe but you cna just hit "start" and start typing "visual studio installer")

Lick "modify" and simply re-run it with all existing components checked.

Just make sure "ASP.NET Web development" is checked.

Upvotes: 0

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.

Upvotes: 0

Joe Kehnast
Joe Kehnast

Reputation: 127

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

Upvotes: 0

Mike Strother
Mike Strother

Reputation: 331

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

Upvotes: 1

Alex Narbut
Alex Narbut

Reputation: 186

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

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

Upvotes: 1

Jenish Zinzuvadiya
Jenish Zinzuvadiya

Reputation: 1085

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

Update-Package Microsoft.AspNet.Mvc

Upvotes: 8

papadoo
papadoo

Reputation: 126

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}

Upvotes: 3

t_plusplus
t_plusplus

Reputation: 4209

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):

enter image description here

Upvotes: 1

user2825149
user2825149

Reputation: 1

VS2012 Context menu to Add Controller/View missing

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

UnInstall-Package Microsoft.AspNet.WebApi 

Upvotes: -2

Dillon
Dillon

Reputation: 707

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

Upvotes: 1

isxaker
isxaker

Reputation: 9486

For older version

{F85E285D-A4E0-4152-9332-AB1D724D3325}

Upvotes: 0

Bjorn Vdkerckhove
Bjorn Vdkerckhove

Reputation: 745

For people using MVC 5, add this key

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

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

Upvotes: 9

dragy
dragy

Reputation: 187

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.

Upvotes: 1

Ali Adravi
Ali Adravi

Reputation: 22743

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};

Upvotes: 33

Darin Dimitrov
Darin Dimitrov

Reputation: 1038940

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.

Upvotes: 117

Don
Don

Reputation: 39

Answer 2 was correct just wrong guid

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

is what you need for MVC in VS2010

Upvotes: 3

Nathan Taylor
Nathan Taylor

Reputation: 24606

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

Upvotes: 0

Related Questions