MVC后台绑定dropdownList

时间:2022-12-28 18:37:01
 public ActionResult Index()
        {             List<SelectListItem> items = new List<SelectListItem>()
            {
                new SelectListItem(){Text="Income", Value="income"},
                new SelectListItem(){Text="Outcome", Value="outcome"},
            };             SelectList generateList = new SelectList(items, "Value", "Text");             ViewBag.drList = generateList;
}   @Html.DropDownList("listname",ViewBag.drList as SelectList,"请选择",new {@class="mylist",@id="listID"})