Asp.net-mvc – Opening an MVC3 project in VS2012

asp.net-mvcasp.net-mvc-3visual studio 2012

I am trying to open an MVC3 solution in a newly installed Visual Studio Express 2012 RC. So far, I've had issues that for some reason VS2012 doesn't know that the projects are MVC projects, so it won't add Views/Controllers. Got past this by adding the following GUID to the ProjectTypeGuids node of the .csproj file of each project in the solution:

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

However, when I open razor views, it shows these errors (among other related ones):

Error    20    The name 'model' does not exist in the current context    c:\Users\willem\Documents\Visual Studio 2010\Projects\000-Orchard Development\src\Orchard.Web\Modules\EventManagement\Views\EditorTemplates\Parts\Event.cshtml    2    2    EventManagement

Error    21    The name 'T' does not exist in the current context    c:\Users\willem\Documents\Visual Studio 2010\Projects\000-Orchard Development\src\Orchard.Web\Modules\EventManagement\Views\EditorTemplates\Parts\Event.cshtml    5    14    EventManagement

Error    22    'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'LabelFor' and no extension method 'LabelFor' accepting a first argument of type 'System.Web.WebPages.Html.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)    c:\Users\willem\Documents\Visual Studio 2010\Projects\000-Orchard Development\src\Orchard.Web\Modules\EventManagement\Views\EditorTemplates\Parts\Event.cshtml    6    11    EventManagement

Intellisense is working in the razor view, but it only gives limited amount of fields for the Html helper method. For instance, none of the model specific methods like LabelFor and TextboxFor.

I have MVC 3 and 4 installed. The solution worked fine in VS2010.

UPDATE:

When adding a new MVC3 project in VS2012, it works fine. So that means it is definately something to do with the project, and not the installation.

UPDATE 2:
I think that the issue is that the view doesn't have access to the referenced libraries in the root config:

<system.web.webPages.razor>
  <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
 <pages pageBaseType="Orchard.Mvc.ViewEngines.Razor.WebViewPage">
    <namespaces>
      <add namespace="System.Web.Mvc" />
      <add namespace="System.Web.Mvc.Ajax" />
      <add namespace="System.Web.Mvc.Html" />
      <add namespace="System.Web.Routing" />
      <add namespace="System.Web.WebPages" />
      <add namespace="System.Linq"/>
      <add namespace="System.Collections.Generic"/>
      <add namespace="Orchard.Mvc.Html"/>
    </namespaces>
  </pages>
</system.web.webPages.razor>

It does at runtime, but the intellilsense and error console doesn't pick it up

Any help is appreciated.

Thanks

Best Answer

For me this problem was resolved by adding:

<add key="webpages:Version" value="1.0.0.0"/>

in my appSettings section of my root web.config

e.g.

 <appSettings>
     <add key="webpages:Version" value="1.0.0.0"/>
     <add key="ClientValidationEnabled" value="true"/>
     <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
  </appSettings>
Related Topic