![Html.DropDownListFor 练习 Html.DropDownListFor 练习](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700)
需要创建一个List<SelectListItem>数据集,如下
使用已经存在FruitCategoryEntity.cs类的IEnumerable<FruitCategory> GetAllFruitCategory()数据集也行。
public IEnumerable<FruitCategory> GetAllFruitCategory()
{
DataTable dt = objBusinessBase.GetDataToDataSet("usp_FruitCategory_GetAll").Tables[];
return DataTableConvertToEnumerable(dt) ;
}
在视图中的Razor语法:
@Html.DropDownListFor(o=>Model.FruitCategory_nbr,new SelectList(fcEntity.GetAllFruitCategory(),"FruitCategory_nbr","CategoryName"),"选择.....")