asp.net mvc DropDownList 不从数据库取数据显示
action:
public ActionResult Register()
{
var items = new List<SelectListItem>()
{
(new SelectListItem() {Text = "保密", Value = "0", Selected = true}),
(new SelectListItem() {Text = "男", Value = "1", Selected = false}),
(new SelectListItem() {Text = "女", Value = "2", Selected = false})
};
ViewData["items"] = items;
return View();
}
view:
<label for="sex">性别:</label>
<%=Html.DropDownList("items")%>