“The name 'HTML' does not exist in the current context” in MVC 3 Views

后端 未结 21 2221
野的像风
野的像风 2020-12-15 03:50

I´m starting to use \"MVC 3\" but I´m facing some little problems. In my Views, when I code something like this:

@if(Request.IsAuthenticated) {
    

        
相关标签:
21条回答
  • 2020-12-15 04:17

    You could try some following point:

    • Close the View with the false errors.
    • Close visual studio.
    • open project again.
    • clean your solution
    • Rebuild your solution.

    hopefully you will not get any of the similar errors now.

    If you still have same problem. than Please check following steps.

    • Make sure you have web.config file inside view folder. Becuase MVC has two web.config. one for solution and other one for project.

    Your web.config file will seems like this which is inside views folder.

    <?xml version="1.0"?>
    
    <configuration>
      <configSections>
        <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
          <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
        </sectionGroup>
      </configSections>
    
      <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.7.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" />
            <add namespace="Your Project Name" />
          </namespaces>
        </pages>
      </system.web.webPages.razor>
    
      <appSettings>
        <add key="webpages:Enabled" value="false" />
      </appSettings>
    
      <system.webServer>
        <handlers>
          <remove name="BlockViewHandler"/>
          <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
        </handlers>
      </system.webServer>
    
      <system.web>
        <compilation>
          <assemblies>
            <add assembly="System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
          </assemblies>
        </compilation>
      </system.web>
    </configuration>
    

    It worked for me. and hope for you also.

    0 讨论(0)
  • 2020-12-15 04:17

    For me, I just restarted my Visual Studios and everything got fixed.

    0 讨论(0)
  • I'm using ASP .net core. Solved mine by upgrading Microsoft.AspNetCore.Mvc from 1.1.2 to 1.1.3.

    0 讨论(0)
  • 2020-12-15 04:28

    Clean your solution and Under references. Then set the follow property:

    System.Web.MVC file to Copy Local = True.
    
    0 讨论(0)
  • 2020-12-15 04:29

    I tried to remove the project that is still in trouble from solution and add it back again, after which the problem had been gone.

    0 讨论(0)
  • 2020-12-15 04:30

    All I had to do was close all views that were open in the editor and rebuild.

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