这让我很沮丧,但我已经尝试了所有常见的解决方案,但都没有奏效。
我的 razor 页面在部署后抛出此异常:
<块引用>HtmlHelper 不包含 BeginForm 的定义
这是我得到的:
编辑.cshtml:
@using (Html.BeginForm("UploadTenantFile", "TenantSubscriptions", FormMethod.Post, new { enctype = "multipart/form-data", @class = "noprint" }))
{
<h4>Upload New File</h4><br />
@Html.AntiForgeryToken()
...
}
/Views/ 中的 web.config:
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="BetterCompliance.CompliancePortal.Web.Views.CompliancePortalWebViewPageBase">
<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="BetterCompliance.CompliancePortal.Web" />
</namespaces>
</pages>
</system.web.webPages.razor>
在根 web.config 中:
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
</dependentAssembly>
值得一提的是,有几行,没有重载的相同方法可以正常工作:
@using (Html.BeginForm())
{