MVC 中DropDownList 用法

时间:2020-12-16 14:27:04

MVC 中DropDownList  用法

后台

 Dictionary<string, int> dc = new Dictionary<string, int>();
dc.Add("订单提交", );
dc.Add("订单确认", );
dc.Add("已入库", );
dc.Add("代付款", );
dc.Add("已支付", );
dc.Add("出库", );
SelectList items = new SelectList(dc, "Value", "Key");
ViewBag.GenderList = items;

前台

 @Html.DropDownList("GenderList", (SelectList)ViewBag.GenderList, "--请选择--")

方式二

 ViewData["city"] = new List<SelectListItem>()
{
new SelectListItem(){ Selected=false , Text="北京", Value=""},
new SelectListItem(){ Selected=false , Text="上海", Value=""},
new SelectListItem(){ Selected=false , Text="广州", Value=""},
}; ==================================
@Html.DropDownList("city")