Html Helper Extensions not being found
I'm using the release version of ASP.net MVC and I seem to be getting this error a lot
'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?)
which is very odd since I can browse to System.Web.Mvc.HtmlHelper and all the extension methods are there. Even stranger is that I can compile and all the errors go away, however as soon as I start editing again they show back up. I am including
<%@ Import Namespace="System.Web.Mvc" %>
<%@ Import Namespace="System.Web.Mvc.Html" %>
in my site.master file which I found suggested somewhere but that doesn't seem to help. Any ideas? The intelisense isn't finding the extension methods either.
First, check if you are using RenderPartial method right:
<% Html.RenderPartial(...); %>
Second, check your web.config contains:
<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>
Do you use
<% Html.RenderPartial("~/Views/Project/Projects.ascx", ViewData); %>
or
<%=Html.RenderPartial("~/Views/Project/Projects.ascx", ViewData); %>
?
it's supposed to be the first one, without "=". I'm not sure if that will solve it but I remember they changed something that way.
Also see: 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'RenderPartial' - ASP.Net MVC
You may think this is dumb, but I just had the same problem. I had a working MVC app, running 1.0.0.0 and all of a sudden it stopped working giving me the same RenderPartial isn't in the definition. Well it turns out that while I was going crazy cleaning up my web.config, I removed this section. When I re-added it, everything worked again. I'm sure this has something to do with how the class extensions load during runtime.
Anyway, re-adding this to my web.config worked on my machine. ;)
<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>
链接地址: http://www.djcxy.com/p/42672.html
上一篇: 获取iPhone状态栏高度