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=22.214.171.124, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> </assemblies> </compilation> <pages> <namespaces> <add namespace="System.Web.Mvc.Html" /> </namespaces> </pages> </system.web>
You may think this is dumb, but I just had the same problem. I had a working MVC app, running 126.96.36.199 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=188.8.131.52, 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=184.108.40.206, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <providerOption name="CompilerVersion" value="v3.5"/> <providerOption name="OptionInfer" value="true"/> <providerOption name="WarnAsError" value="false"/> </compiler> </compilers> </system.codedom>
Do you use
<% Html.RenderPartial("~/Views/Project/Projects.ascx", ViewData); %>
<%=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.