<div class="form-group">
@Html.LabelFor(model => model.Title, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("Title", new SelectList(Enum.GetValues(typeof(OnLineShoppingCart.Models.Supplier.Salutation))), "Select The Salutation", new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" })
</div>
</div>
答案 0 :(得分:2)
试试这个:
<强>控制器强>
IEnumerable<SelectListItem> TitleList = null;
TitleList = (from m in Enum.GetValues(typeof(Titles)).Cast<Titles>() select m).AsEnumerable().Select(m => new SelectListItem() { Text = m.ToString(), Value = m.ToString() });
ViewBag.TitleList = new SelectList(TitleList, "Value", "Text");
查看强>
<div class="form-group">
@Html.LabelFor(m => m.Title, new { @class = "col-md-2 control-label" })
<div class="col-md-6">
@Html.DropDownListFor(m => m.Title, new SelectList(ViewBag.TitleList, "Value", "Text"), "--Select Title--", new { @class = "form-control", placeholder = "Title"})<br />
@Html.ValidationMessageFor(m => m.Title, null, new { @class = "text-danger" })
</div>
</div>