2

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.

5 Answers 5

4

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

1

Just like John Foster said you have to edit the .csproj file manually. However, I needed a different guid and some additional elements (at least for Visual Studio 2012) otherwise I got an error dialog after the Add->View that said "Parameter cannot be null. Parameter name path1". Here's what I did:

  1. Right-click project -> "Unload Project"
  2. Right-click project -> "Edit .csproj"
  3. Add {E3E379DF-F4C6-4180-9B81-6769533ABE47}; to Project\PropertyGroup\ProjectTypeGuids. Mine looks like:

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

  4. Ensure the following elements exist in Project\PropertyGroup:

    <MvcBuildViews>false</MvcBuildViews>

    <FileUpgradeFlags></FileUpgradeFlags>

    <UpgradeBackupLocation></UpgradeBackupLocation>

    <TargetFrameworkProfile />

Comments

0

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.