@html.dropdown用法

controller
1
List<SelectListItem> itemList = new List<SelectListItem>() 2 { 3 new SelectListItem (){Text ="1",Value="2"}, 4 new SelectListItem (){Text="2",Value="2"} 5 6 }; 7 itemList.Add(itemList[0]); 8 SelectList select = new SelectList(itemList, "Value", "Text"); 9 ViewData["select"] = select;

视图:

1 @Html.DropDownList("select", ViewData["select"] as SelectList, new {@class = "form-control no-padding-hr", style = "border-radius: 0"})

如过出现“select”名字报错,那就是itemlist为空,添加一个验证就ok了:

 

“select”   会生成 html的select标签的name和id,这个标签在from表单中的话,name值和Controller 中的ActionResult的参数名相同就可以传值提交处理

 

 

 

 

 

 

 


                                                                    未完待续

posted @ 2018-09-07 17:15  鹤哥只手遮天  阅读(1334)  评论(0编辑  收藏  举报