Friday, October 22, 2010

How To Solve System.Web.Mvc.HtmlHelper' does not contain a definition for 'RenderPartial' and no extension method 'RenderPartial'

Sometimes there are errors when you build in ASP.NET MVC that just make you want to shoot your own computer! You resist the urge of course (I hope), but the desire is still there! While I was creating an extension helper in ASP.NET MVC using Visual Studio 2010, I came across this error:

How To Solve 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?)

Ummm.....NO I am NOT missing a using directive or assembly reference - thank you very much! Well actually I was - LOL. I'm using MVC2. It seems that it wants an additional reference to reference RenderPartial now.

Here is a list of the usings I was using
(notice that wording - "usings I was using" - that makes me laugh - I crack myself up sometimes!) -

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web;
using System.Reflection;

The using statements above SHOULD be enough to allow me to use RenderPartial. Unfortunately, I had to add ONE MORE using statement to make it work -

using System.Web.Mvc.Html;

That solved the issue! Why does Microsoft change little things like this? Do they do it just to drive people crazy?

Smooches,

Kila


PROBLEM:
How To Solve 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?)

SOLUTION:
Make sure you are referencing MVC in your web.config, make sure you have a mvc using statements listed above in your file and make sure you add the following item to that list of using statements.

using System.Web.Mvc.Html;

2 comments:

Anonymous said...

Thanks for this - I thought I was going crazy myself!

Muruganantham Durairaj said...

thanks for help.. this is really useful