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))
精彩评论