//后台 public ActionResult OrderAdd() { var items = new List<SelectListItem>() { (new SelectListItem(){Text = "男", Value = "Male"}), (new SelectListItem(){Text = "女", Value = "female"}) }; ViewBag.sexList = items; return View(); }
//前端 //默认为空 @Html.DropDownList("sexList", ViewBag.sexList as List<SelectListItem>,"") //默认为第一个值,也就是 "男" @Html.DropDownList("sexList", ViewBag.sexList as List<SelectListItem>)
时间: 2024-10-18 07:39:52