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")%>

posted @ 2009-08-17 22:08  芽芽陆  阅读(441)  评论(0编辑  收藏  举报