Razor Views not seeing System.Web.Mvc.HtmlHelper

后端 未结 22 955
我在风中等你
我在风中等你 2020-11-27 05:27

I am in the process of upgrading to MVC4. I have followed the instructions at http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253806 but in my Razor views and layou

相关标签:
22条回答
  • 2020-11-27 06:10

    As for me, it was a stupid deployment mistake: Web projects can have more than one web.config. It was working on the developer's machine and not in production, but we were not realising that the deployment script only grabbed the Web.config file at the root, and it didn't copy the Web.config file in the Views folder.

    0 讨论(0)
  • 2020-11-27 06:12

    As a variation on a theme, I could have sworn up and down that my Views\Web.config was correct:

    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    

    But I in fact needed to reference Version=4.0.0.1, not Version=4.0.0.0 because of that security update that got pushed out a while back.

    0 讨论(0)
  • 2020-11-27 06:15

    I had the same issue when updating to MVC 5 and it was solved by updating the web.config inside the Views folder.

    <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.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.Optimization"/>
        <add namespace="System.Web.Routing" />
      </namespaces>
    </pages>
    

    The host -> factoryType was set to version:4.0.0.0 hope this helps anyone.

    0 讨论(0)
  • 2020-11-27 06:16

    Right, I've been trying to fix this issue for sometime. I've used all the solutions in the various Stack Overflow topics regarding this and none seemed to be working.

    I have just fixed the issue this morning. After you gave fixed the web.config for both the project and the views, making sure all the .dll versions are matching with what you have in the references folder. You will need to unload the project, edit the .csproj, and then update all the .dll versions in that file.

    System.Web.Helpers
    System.Web.Mvc
    System.Web.WebPages
    

    Hope this helps, as I have finally fixed this issue! No more red squiggly lines.

    This has also fixed the context menu issue I was having where, I wasn't getting the option to add a controller, view etc.

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