htmlhelper不包含beginform的定义。 [英] htmlhelper does not contain a definition for beginform.

查看:229
本文介绍了htmlhelper不包含beginform的定义。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将我的项目更新为mvc 5,EF 6.我通过包控制台管理器(update-package)更新了所有软件包。现在我看到每个视图/局部视图/布局中有关html助手的大量警告。 br />


以下是一些错误:



当前上下文中不存在ViewBag这个名称

当前上下文中不存在Styles这个名称

当前上下文中不存在Scripts这个名称

'系统.Web.WebPages.Html.HtmlHelper'不包含'Partial'的定义,也没有扩展方法'Partial'接受类型'System.Web.WebPages.Html.HtmlHelper'的第一个参数可以找到(你错过了吗?使用指令或程序集引用?)

'System.Web.WebPages.Html.HtmlHelper'不包含'ActionLink'的定义......

'系统。 Web.WebPages.Html.HtmlHelper'不包含'BeginForm'的定义......

'System.Web.WebPages.Html.HtmlHelper'不包含'AntiForgeryToken'的定义......

这是views / webconfig:





i recently updated my project to mvc 5, EF 6. i updated all the packages via package console manager (update-package).Now i see tons of warnings about the html helpers in every view/partial view/layout.

These are some of the errors:

The name 'ViewBag' does not exist in the current context
The name 'Styles' does not exist in the current context
The name 'Scripts' does not exist in the current context
'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'Partial' and no extension method 'Partial' accepting a first argument of type 'System.Web.WebPages.Html.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)
'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'ActionLink' ...
'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'BeginForm' ...
'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'AntiForgeryToken' ...
Here is the views/webconfig:


<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <httpRuntime targetFramework="4.5" />
    <compilation debug="true" targetFramework="4.5">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <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" />
      </namespaces>
    </pages>
    <authentication mode="Forms">
      <forms loginUrl="~/Home/LoginPage" timeout="2880" />
    </authentication>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
  <connectionStrings>
    <add name="EMSEntities2" connectionString="metadata=res://*/Models.EMSEntities.csdl|res://*/Models.EMSEntities.ssdl|res://*/Models.EMSEntities.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=VERUDIX43\SQLEXPRESS;Initial Catalog=EMS;Integrated Security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

推荐答案

验证您是否具有对System.Web.WebPages的正确引用或将其添加到web.config



verify you have the right reference to System.Web.WebPages or add this to web.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="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" />
            <add namespace="WebApp.WebUI" />
        </namespaces>
    </pages>
</system.web.webPages.razor>


这篇关于htmlhelper不包含beginform的定义。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆