Visual studio showing syntax errors in razor statements but works

后端 未结 2 609
野趣味
野趣味 2020-12-20 23:39

I\'ve a project in MVC 3. It works perfectly and each time I build it, it succeeds. However, Visual Studio insist in showing compile errors in views in each razor syntax. Fo

相关标签:
2条回答
  • 2020-12-21 00:15

    Open your web.config file located inside of Views folder and add this section if it's missing:

    <system.web.webPages.razor>
      <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <pages pageBaseType="System.Web.Mvc.WebViewPage">
        <namespaces>
          <add namespace="System.Web.Mvc" />
          <add namespace="System.Web.Mvc.Ajax" />
          <add namespace="System.Web.Mvc.Html" />
          <add namespace="System.Web.Routing" />
        </namespaces>
      </pages>
    </system.web.webPages.razor>
    
    0 讨论(0)
  • 2020-12-21 00:29

    I've solved it!

    The project was created when the computer didn't have MVC 4 installed yet. After installing it, for some reason, it kept working (despite this).

    So what I did was make the changes that should be made in MVC 3 project after installing MVC 4: see here

    After that, it compiled and the errors disappeared, however there was an error with the versions of some libraries (System.Web.WebPages, System.Web.WebPages.Razor, and some others). That turned out to be because they had Copy Local set to True. After changing that everything started working great.

    0 讨论(0)
提交回复
热议问题