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 05:58
    *<system.web>
    <compilation debug="true" targetFramework="4.5">
        <assemblies>
            <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        </assemblies>
    </compilation>*
    

    This configuration is missing, add it and set appropriate version of assemblies

    0 讨论(0)
  • 2020-11-27 05:59

    For those of you suffering with this after migrating a project from VS 2013 to VS 2015, I was able to fix this issue by installing the ASP.NET tools update from https://visualstudiogallery.msdn.microsoft.com/c94a02e9-f2e9-4bad-a952-a63a967e3935/file/77371/6/AspNet5.ENU.RC1_Update1.exe?SRC=VSIDE&UPDATE=TRUE.

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

    You need to copy Views/Web.config to /Shared. This will tell Razor to use the MVC base type & parser. You can read more here: http://blog.slaks.net/2011/02/dissecting-razor-part-3-razor-and-mvc.html

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

    Having tried everything in vain, I discovered that in my case it wasn't working because an incorrect attribute value in Web Project csproj file. When I change ToolsVersion to 14, which matches my current IDE version (i.e. Visual Studio 2015), everything worked like a charm:

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition=
      .....
    
    0 讨论(0)
  • 2020-11-27 06:02

    My situation only occurred after I created a custom class called BaseViewPage that overrode the WebViewPage class. I initially added the following to my Main Web.confg file:

    <pages pageBaseType="ZooResourceLibrary.Web.Support.BaseViewPage">
    

    And the same to the View folders web.config file:

    <pages pageBaseType="ZooResourceLibrary.Web.Support.BaseViewPage">
    

    I tried many of the other answers and none did the trick while still allowing me to keep my BaseViewPage class. The way I fixed it was to remove the pageBaseType attribute from the Main Web.config file only. Keep it in the View web.config.

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

    I tried all the solutions here but none of them worked for me. Again, my site runs fine but I don't have intellisense and get red wavy lines under a lot of things in my views that Visual Studio does not recognize, one of them being Html.BeginForm(), as well as anything having to do with ViewBag.

    I'm working with a new MVC 5 project. After hours of comparing web.config lines, I finally found what fixed it for me.

    My web.config in my root had the following line:

    <system.web>
      <compilation debug="true" targetFramework="4.5" />
    
      <!-- ... -->
    </system.web>
    

    I compared to a previous project not using MVC 5, and copied over a block I noticed was missing from the new one, which was the following:

    <system.web>
      <compilation debug="true" targetFramework="4.5">
        <assemblies>
          <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
          <add assembly="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
          <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
          <add assembly="System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
          <add assembly="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        </assemblies>
      </compilation>
    
      <!-- ... -->
    </system.web>
    

    I copied the above block over to my new project's web.config in the root, changing the versions to match the numbers for each assembly found in my project references (right-clicking each reference mentioned and selecting "Properties", "Version" is given at the bottom of the properties window for the selected reference).

    After implementing the above, I now have intellisense and don't get any unknown red lines under things like Html.BeginForm, ViewBag.Title, etc.

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