剃刀-在下拉列表中强制转换为IEnumerable

问题描述

|| 如何在MVC 3中将对象从ViewBag投射到IEnumerable? 我想这样做soethnig:
@Html.DropDownListFor(model => model.CategoryID,@(IEnumerable<SelectListItem>)ViewBag.CategoriesList)
下拉列表将IEnumerable作为参数,但是我不知道如何正确地将其强制转换。上面的代码返回错误。     

解决方法

@Html.DropDownListFor(
    model => model.CategoryID,(IEnumerable<SelectListItem>)ViewBag.CategoriesList
)
    ,
@Html.DropDownList(\"categoryId\",new SelectList(ViewBag.Categories as System.Collections.IEnumerable,\"categoryId\",\"categoryName\",Model.categoryId))