代码改变世界

Html.DropDownList 的用法

2011-02-22 17:01  CuiWenKe  阅读(803)  评论(0编辑  收藏  举报

参考:1  http://anghoo.blogbus.com/tag/Html.DropDownList/

参考:2  http://stackoverflow.com/questions/810265/integrating-jquery-with-ajax-using-mvc-for-ddl-html-dropdownlist

Control端:

public PartialViewResult SelectShiftView(string id)
 {
         List<SelectListItem> items = new List<SelectListItem>(); 
         items.Add(new SelectListItem { Text = "所有轮班制度", Value = "all_view" });
         items.Add(new SelectListItem { Text = "轮班制度2", Value = "view2" });
         this.ViewData["ddlShift"] = items;
         this.ViewData["selected"] = "selected ?? 1";
         return PartialView();
  }

View 端:

  <%= Html.DropDownList("ddlShift", ViewData["ddlShift"] as SelectList, "请选择", new { id = "ddlShift" })%>