开发者

Razor - cast IEnumerable in dropdownlist

How to cast in MVC 3 an object from ViewBag to IEnumerable ?

i would like to do soethnig like that:

@Html.DropDownListFor(model => model.CategoryID, @(IEnumerable<SelectListItem>)ViewBag.CategoriesList)
开发者_如何学C

the dropdownlist takes IEnumerable as an argument, but I don't know how to cast it properly. The above code returns an error.


@Html.DropDownListFor(
    model => model.CategoryID, 
    (IEnumerable<SelectListItem>)ViewBag.CategoriesList
)


@Html.DropDownList("categoryId",
            new SelectList(ViewBag.Categories as System.Collections.IEnumerable,
            "categoryId", "categoryName", Model.categoryId))
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜