开发者

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;
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜