I’m trying to implement a editor template for Nullable<bool> to instead to appear true or false, appears “Si” or “No”. This is what I have so far.
@model Nullable<bool>
@{
var listItems = new List<System.Web.UI.WebControls.ListItem>();
listItems.Add(new System.Web.UI.WebControls.ListItem{Text="Si", Value="true"});
listItems.Add(new System.Web.UI.WebControls.ListItem{Text="No", Value="false"});
}
@Html.DropDownList( model => model.Value, listItems)
And It’s throws this error Cannot convert lambda expression to type 'string' because it is not a delegate type. I can’t see the error what i’m doing wrong???
The
DropDownListhelper takes a string as first argument, not a lambda expression. UseDropDownListForand make sure that the second argument is anIEnumerable<SelectListItem>, which your code isn’t:You can forget about
System.Web.UI.WebControls.ListItemin an ASP.NET MVC application. That’s a classic WebForms stuff.