我正在使用asp.net mvc我想添加一个dropdown list
,它包含一个静态值和来自数据库的其他值
@Html.DropDownListFor(Function(model) model.nDepartmentID,
New SelectList(ViewBag.txt, "Value", "Text"), New With
{Key .[class] = "select1",Key .style = "width: 150px;"})
答案 0 :(得分:0)
使用以下代码
@Html.DropDownListFor(m => m.nDepartmentID, (SelectList)ViewBag.DepartmentList, "Select Any Department", new {@class="select1",@style="width: 150px;" })
你的控制器动作将是
public ActionResult ShowPage()
{
var deptmnts=db.Departments.ToList();
ViewBag.DepartmentList=new SelectList(deptmnts,"ID","DepartmentName");
retun View();
}