//获取直属父级列表 var parents = _MemberEditDTOService.GetParents(); var parentsItems = parents.Result.Select(s => new SelectListItem() { Text = s.MemberName, Value = ((int)s.Id).ToString() }).ToList(); //parentsItems.First(t => t.Value.Equals("0")).Text = "--请选择--"; ViewBag.parentsSelectItems = parentsItems;
前端:
@Html.DropDownList("MemberTypesSelectItems", ViewBag.MemberTypesSelectItems as SelectList, new { id = "memberTypes", Class = "form-control ", style = "display: inline-block;" })
或者
@Html.DropDownList("BusinessDepartment", new List<SelectListItem> { (new SelectListItem() {Text = "--请选择--", Value = "", Selected = true}), (new SelectListItem() {Text = "业务部1", Value = "1", Selected = false}), (new SelectListItem() {Text = "业务部2", Value = "0", Selected = false}), }, new { @style = "99%;" }, new { id = "BusinessDepartment" })
或者
<select id="ddlUserType" class="form-control " style=" 90px; display: inline-block;"> @foreach (var userType in ViewBag.UserType) { <option value="@userType.Value">@userType.Text</option> } </select>