第一种方法:
List<SelectListItem> statusItems = new List<SelectListItem>();
statusItems.Add(new SelectListItem() { Text = "==全部==", Value = "0", Selected = "0" == status });
statusItems.Add(new SelectListItem() { Text = "未完成", Value = "1", Selected = "1" == status });
statusItems.Add(new SelectListItem() { Text = "已完成", Value = "2", Selected = "2" == status });
ViewBag.statusOptions = statusItems;
完成状态:
@Html.DropDownList("Text",@ViewBag.statusOptions as IEnumerable<SelectListItem>, new { @id = "StatusID" })
第二种方法:
@Html.DropDownList("myList",new SelectList(new[]{"A","B"}),"Choose")
第三种方法:
List<SelectListItem> listItem = new List<SelectListItem>();
listItem.Add(new SelectListItem() { Text = "是", Value = "1"});
listItem.Add(new SelectListItem() { Text = "否", Value = "0"});
ViewData["List"]=new SelectList(listItem,"Value","Text","");
@Html.DropDownList("List",ViewData["List"] as SelectList,"请选择")