displaying a listbox using Html.List, and I have a List<User> collection
Is a List enumerable?
Html.List("mylistbox", Model.UserList);
doesnt' se开发者_运维百科em to be working, where UserList is a List collection.
Are you using the DropDownList helper?
<%= Html.DropDownList("Layers", Model.GetLayersOptions("2"))%>
Make sure your Model.UserList property is of type IEnumerable<T>
. Here's my implementation:
public virtual IEnumerable<SelectListItem> GetLayersOptions(string defaultSt)
{
var items = new List<SelectListItem>
{
new SelectListItem() {Text = "1", Value = "1"},
new SelectListItem() {Text = "2", Value = "2"},
new SelectListItem() {Text = "12", Value = "12"}
};
Utils.SetSelectedItem(items, defaultSt, () => Layers);
return items;
}
精彩评论