标签:
使用列表的指定项、数据值字段、数据文本字段和选定的值来初始化 SelectList 类的新实例。
控制器代码:
public class StoreController : Controller { public ActionResult Index() { var arr = new List<object>(); arr.Add(new{name="1308",id=7}); arr.Add(new{name="1307",id=8}); var list = new SelectList(arr,"id","name",1309); ViewBag.list = list; return View(); } }
视图代码:
@{ ViewBag.Title = "Index"; } <h2>Index</h2> @using (Html.BeginForm("Index", "Store", FormMethod.Post)) { @Html.DropDownList("sl",(SelectList)@ViewBag.list); }
标签:
原文地址:http://www.cnblogs.com/772933011qq/p/4453804.html