【问题标题】:Html Helper Extensions not being found找不到 Html 帮助程序扩展
【发布时间】:2009-05-18 05:47:19
【问题描述】:

我正在使用 ASP.net MVC 的发布版本,我似乎经常收到此错误

'System.Web.Mvc.HtmlHelper' does not contain a definition for 'RenderPartial' and no extension method 'RenderPartial' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)

这很奇怪,因为我可以浏览到 System.Web.Mvc.HtmlHelper 并且所有扩展方法都在那里。更奇怪的是,我可以编译并且所有错误都消失了,但是一旦我再次开始编辑,它们就会重新出现。我包括

<%@ Import Namespace="System.Web.Mvc" %>
<%@ Import Namespace="System.Web.Mvc.Html" %>

在我发现某处建议的 site.master 文件中,但这似乎没有帮助。有任何想法吗?智能感知也没有找到扩展方法。

【问题讨论】:

    标签: asp.net-mvc extension-methods


    【解决方案1】:

    首先,检查你使用的RenderPartial方法是否正确:

    <% Html.RenderPartial(...); %>
    

    其次,检查你的 web.config 包含:

    <system.web>
        <compilation>
            <assemblies>
                <add assembly="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            </assemblies>
        </compilation>
        <pages>
            <namespaces>
                <add namespace="System.Web.Mvc.Html" />
            </namespaces>
        </pages>
    </system.web>
    

    【讨论】:

      【解决方案2】:

      你会用吗

      &lt;% Html.RenderPartial("~/Views/Project/Projects.ascx", ViewData); %&gt;

      &lt;%=Html.RenderPartial("~/Views/Project/Projects.ascx", ViewData); %&gt;

      ?

      它应该是第一个,没有“=”。 我不确定这是否能解决问题,但我记得他们以这种方式改变了一些东西。

      【讨论】:

      • 只是新项目自带的标准site.master
      【解决方案3】:

      另见:'System.Web.Mvc.HtmlHelper' does not contain a definition for 'RenderPartial' - ASP.Net MVC

      您可能认为这很愚蠢,但我也遇到了同样的问题。我有一个工作的 MVC 应用程序,运行 1.0.0.0,突然间它停止工作,给我同样的 RenderPartial 不在定义中。事实证明,当我疯狂地清理我的 web.config 时,我删除了这一部分。当我重新添加它时,一切都恢复了。我确信这与运行时类扩展的加载方式有关。

      无论如何,将它重新添加到我的 web.config 在我的机器上工作。 ;)

      <system.codedom>
          <compilers>
              <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4"
                           type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
                  <providerOption name="CompilerVersion" value="v3.5"/>
                  <providerOption name="WarnAsError" value="false"/>
              </compiler>
      
              <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4"
                           type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
                  <providerOption name="CompilerVersion" value="v3.5"/>
                  <providerOption name="OptionInfer" value="true"/>
                  <providerOption name="WarnAsError" value="false"/>
              </compiler>
          </compilers>
      </system.codedom>
      

      【讨论】:

        猜你喜欢
        • 2014-12-06
        • 2011-01-26
        • 2013-08-09
        • 2012-05-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-28
        • 1970-01-01
        相关资源
        最近更新 更多