看一下Controller例子
[ChildActionOnly] public List<SelectListItem> LoadItemStatus() { List<SelectListItem> items = new List<SelectListItem>() { new SelectListItem() { Value = "", Text = "--所有--" }, new SelectListItem() { Value = "待审核", Text = "--待审核--" }, new SelectListItem() { Value = "审核通过", Text = "--审核通过--" }, new SelectListItem() { Value = "审核不通过", Text = "--审核不通过--" } }; return items; } public ActionResult Index() { List<SelectListItem> items = new List<SelectListItem>() { new SelectListItem() { Value = "", Text = "--所有--" }, new SelectListItem() { Value = "待审核", Text = "--待审核--" }, new SelectListItem() { Value = "审核通过", Text = "--审核通过--" }, new SelectListItem() { Value = "审核不通过", Text = "--审核不通过--" } }; ViewData["Categories"] = new SelectList(items, "Text", "Value"); return View(); }
看一下
@*@Html.DropDownList("Category", ViewData["Categories"] as SelectList,"--请选择--",new { @class = "my-select-css-class" } )*@