//动态获取数据库内容并赋值给下拉框
.cs代码
IEnumerable<SelectListItem> items=db.Voice.Select(c=>new SelectListItem
{
Value=SqlFunctions.StringConvert((double)c.ID),
Text=c.Name
});
ViewData["ID"]=items;
return View();
html:
@Html.DropDownList("ID")
//动态获取数据库内容并赋值给下拉框
.cs代码
IEnumerable<SelectListItem> items=db.Voice.Select(c=>new SelectListItem
{
Value=SqlFunctions.StringConvert((double)c.ID),
Text=c.Name
});
ViewData["ID"]=items;
return View();
html:
@Html.DropDownList("ID")