MVC 中DropDownList 用法

MVC 中DropDownList  用法

后台

1 Dictionary<string, int> dc = new Dictionary<string, int>();
2 dc.Add("订单提交", 0);
3 dc.Add("订单确认", 1);
4 dc.Add("已入库", 2);
5 dc.Add("代付款", 3);
6 dc.Add("已支付", 4);
7 dc.Add("出库", 5);
8 SelectList items = new SelectList(dc, "Value", "Key");
9 ViewBag.GenderList = items;
View Code

前台

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

 

 方式二

 ViewData["city"] = new List<SelectListItem>()
            {
              new SelectListItem(){ Selected=false , Text="北京", Value="1"},
               new SelectListItem(){ Selected=false , Text="上海", Value="2"},
                new SelectListItem(){ Selected=false , Text="广州", Value="3"},
            };

==================================
@Html.DropDownList("city")
View Code

 

posted @ 2015-09-04 12:02  每天进步一点点!  阅读(475)  评论(0编辑  收藏  举报