Access HtmlHelper methods in the HtmlHelper extension method - ASP.NET MVC RC2

I am trying to build an HtmlHelper extension in ASP.NET MVC RC2. This code worked fine in Preview 5, but no longer works in RC2, and I'm trying to figure out why. Here is the code:

public static string EmptyDropDownList(this HtmlHelper htmlHelper, string name, object htmlAttributes) { return htmlHelper.DropDownList(name, new SelectList(new string[0]), htmlAttributes); } 

The problem is that I cannot access all the htmlHelper methods from the extension method. So htmlHelper.DropDownList could not be found.

Any suggestions?

+4
source share
2 answers

You need to include the System.Web.Mvc.Html namespace, since most HtmlHelper methods are indeed extensions defined in the classes in this namespace.

You can find RC1 (and presumably soon RC2 source code too) at www.codeplex.com/aspnet . Go to the source code tab and go to the MVC source tree.

+11
source

Two options:

a. Add to the page using "Use" using the razor view page (mvc 3 and mvc 4) for example

  @using UrWeb.Helpers 

OR

b. Add to the internal section namespaces web.config for example

  <add namespace="UrWeb.Helpers"/> 
0
source

All Articles