I am trying to populate a dropdown list from a database mapped with Linq-2-SQL, using ASP.NET MVC 2, and keep getting this error.
I am so confused because I am decla
Try adding a string for the name of your dropdown list as the first parameter, and get the item out of your viewdata:
<%= Html.DropDownList("SomeDropdownName", (IEnumerable)ViewData["basetype"]) %>
Here is also an extension method you can use so the dropdown list is set up in a similar style to how you have done your other controls:
public static string DropDownList(this HtmlHelper htmlHelper, Expression> expression, IEnumerable selectList, string optionLabel)
where TModel : class
{
string inputName = ExpressionHelper.GetInputName(expression);
return htmlHelper.DropDownList(inputName, selectList, optionLabel);
}
For example
<%= Html.DropDownList(x => x.BaseType, (IEnumerable)ViewData["basetype"], "")%>