I have created a custom html helper for an mvc5 application I am working on to create a dropdownlist for countries
public static MvcHtmlString CountryDropDownListFor<TModel, TEnum>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TEnum>> expression, string css, bool displayPleaseSelect = true)
{
var countries = GetCountries();
var list = countries.Select(c => new SelectListItem()
{
Selected = false,
Text = c.Name,
Value = c.Id
}).ToList();
if (displayPleaseSelect)
{
list.Insert(0, new SelectListItem() { Selected = true, Text = "- Please Select -", Value = "0" });
}
return htmlHelper.DropDownListFor(expression, list, new { @class = css });
}
I think my helper looks ok however when adding it to an editor template view like
@Html.CountryDropDownListFor(m=>m.CountryId,"")
I get an error
'System.Web.Mvc.HtmlHelper' does not contain a definition for 'CountryDropDownListFor' and no extension method 'CountryDropDownListFor' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)
Can anyone see what I am doing wrong? The helper is in the same project