由C#的List生成DropDownListItem

            List<ExpressCompany> expressCompanies = ExpressCompanyService.GetAll();
            List<SelectListItem> dropDownListItems = expressCompanies.Select(c => new SelectListItem() { Text = c.Name, Value = c.Code }).ToList();
            dropDownListItems.Add(new SelectListItem { Value = "-", Text = "请选择", Selected = true });
            ViewBag.dropDownList = dropDownListItems;
                        @Html.DropDownList("dropDown", @ViewBag.dropDownList as List<SelectListItem>, new { style = "width:100px;height:20px;line-height:20px;" })

猜你喜欢

转载自blog.csdn.net/hejisan/article/details/83758885