2009-05-18 75 views
7

我使用ASP.net MVC的发行版本,我似乎得到这个错误很多HTML辅助扩展未找到

'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文件,我发现建议的地方,但似乎没有帮助。有任何想法吗? intelisense也没有找到扩展方法。

回答

0

你使用

<% Html.RenderPartial("~/Views/Project/Projects.ascx", ViewData); %>

<%=Html.RenderPartial("~/Views/Project/Projects.ascx", ViewData); %>

它应该是第一个,没有“=”。 我不确定这是否会解决它,但我记得他们改变了这样的事情。

+0

这仅仅是,它有一个新的项目 <%Html.RenderPartial( “LogOnUserControl”)标准的Site.Master; %> – stimms 2009-05-18 16:01:53

4

首先,检查是否正在使用的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> 
+0

是的,这一切看起来是正确的。 – stimms 2009-05-18 16:02:56

0

另见:'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>