8

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

tereško
  • 58,060
  • 25
  • 98
  • 150
hofnarwillie
  • 3,563
  • 10
  • 49
  • 73
  • http://stackoverflow.com/questions/10988328/visual-studio-2012-asp-net-mvc-3-project-razor-view – g.breeze Aug 09 '12 at 08:46
  • http://stackoverflow.com/questions/10988328/visual-studio-2012-asp-net-mvc-3-project-razor-view – g.breeze Aug 09 '12 at 08:47
  • [Related question](http://stackoverflow.com/questions/12623517/accessviolationexception-after-upgrading-mvc3-project-to-vs2012) with different symptoms, same solution. – Drew Noakes Oct 01 '12 at 13:06

5 Answers5

3

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>
timburr
  • 31
  • 1
  • Yes, I had the same issue , http://stackoverflow.com/questions/9471263/mvc-4-beta-side-by-side-installation-error/9551777#9551777 – Tom Stickel Jul 22 '13 at 04:26
2

Check this Link:

http://msdn.microsoft.com/en-us/library/hh266747(v=vs.110).aspx

Make sure you know that project is MVC3. Make sure that project was created with VS2010 with SP1.

bugnuker
  • 3,918
  • 7
  • 24
  • 31
  • Hi, the projects are all on MVC3, so according to the article, VS2012 should just be able to open it (which it does). But the razor views do not have access to all the methods of the Html helper extension methods or any of the View specific properties like ViewBag etc. (please see the update above) – hofnarwillie Jul 11 '12 at 16:14
  • The article says that an you will get an error if it couldn't open the project for any reason, which I didn't get. – hofnarwillie Jul 11 '12 at 16:16
  • You said you can open this in VS 2010? do you still have access to VS 2010? Try to open it on 2010 again and see if that works. – bugnuker Jul 11 '12 at 19:46
  • Yes I can still open it with VS2010, but having the same issues there now. Throwing errors about missing assemblies, etc. – hofnarwillie Jul 12 '12 at 08:16
  • I think that the issue is that the view doesn't have access to the referenced libraries in the root config. It does at runtime, but the intellilsense and error console doesn't pick it up at development. Please see the extract of the root web.config in the update above. – hofnarwillie Jul 12 '12 at 09:40
0

I fixed this by uninstalling MVC4 RC. Doesn't seem compatible with my system (or the 3 other systems I tested with). Will just have to wait for the release version of MVC4

hofnarwillie
  • 3,563
  • 10
  • 49
  • 73
0

You may install both MVC3 and MVC4 on the same computer, please configure in web.config like below

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
      <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="1.0.0.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
      <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
      <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="1.0.0.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>
Marijn
  • 10,367
  • 5
  • 59
  • 80
0

From MVC 4 release notes:

Required updates

  1. In the root Web.config file, add a new entry with the key webPages:Version and the value 1.0.0.0.

  2. In Solution Explorer, right-click the project name and then select Unload Project. Then right-click the name again and select Edit ProjectName.csproj.

  3. Locate the following assembly references: < Reference Include="System.Web.WebPages"/> < Reference Include="System.Web.Helpers" />

Replace them with the following:

<Reference Include="System.Web.WebPages, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/> 
<Reference Include="System.Web.Helpers, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />

4.List item

Save the changes, close the project (.csproj) file you were editing, and then right-click the project and select Reload.

Lucas B
  • 11,793
  • 5
  • 37
  • 50