views:

169

answers:

4

I'm adding some ASP.NET MVC pages to an existing ASP.NET Web Forms project.

I've been able to port over some models, views, and controllers from an MVC project I created and they're working great.

But I'd like to add some new "Strongly Typed" views to my project, but I don't get the New View Wizard in my Web Forms project.

I'm a bit of a newbie when it comes to customizing Visual Studio, so I may be missing something obvious.

A: 

The new View wizard is part of the ASP.Net MVC scaffolding. Your project needs to be created from the ASP.Net MVC project template in order to get this functionality.

Since you're adding it to an old ASP.Net project, probably created with the web application or web site project template, you'll have to get by manually.

womp
+2  A: 

There is a bit of a hack you can do with project files. In your WebForms project file (open it as a normal file) add the following guid under the ProjectTypesGuid node

{603c0e0b-db56-11dc-be95-000d561079b0};

Then add references to System.Web.Routing, Abstractions and MVC and you should be good to go...

Basically it's the reverse of this procedure...

http://weblogs.asp.net/leftslipper/archive/2009/01/20/opening-an-asp-net-mvc-project-without-having-asp-net-mvc-installed-the-project-type-is-not-supported-by-this-installation.aspx

sighohwell
A: 

I just found the answer on the CodeProject blog:

http://www.codeproject.com/KB/aspnet/webformmvcharmony.aspx?msg=3161863#heading0009

It involves manually editing the .csproj file and adding a guid to the list of project types.

Frank Schmitt
A: 

I have also seen this happen when your controller method has a return result of void instead of ActionResult

   //Right click and the context menu will NOT show "Add View"
   public void Details(int id)
   {
      Dinner dinner = dinnerRepository.GetDinner(id);
      if (dinner == null)
         return View("NotFound");
      else
         return View("Details", dinner);
   }

   //Right click and the context menu will show "Add View"
   public ActionResult Details(int id)
   {
      Dinner dinner = dinnerRepository.GetDinner(id);
      if (dinner == null)
         return View("NotFound");
      else
         return View("Details", dinner);
   }
Craig