views:

1658

answers:

1

I am trying to build an HtmlHelper extension in ASP.NET MVC RC2. This code worked fine in Preview 5, but does not work anymore in RC2 and I am trying to understand 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 am unable to access all the methods on htmlHelper from within the extension method. Thus, htmlHelper.DropDownList cannot be found.

Any suggestions?

+8  A: 

You need to include the System.Web.Mvc.Html namespace since most of the HtmlHelper methods are really extensions defined in classes in that namespace.

You can find the RC1 (and, presumably, soon the RC2 source code, too) at www.codeplex.com/aspnet. Click on the source code tab and navigate down to the MVC source code tree.

tvanfosson