我是asp.net MVC的新手.我试图在我的视图页面上使用下拉控件,该页面从枚举中填充.我还想为下拉列表添加自定义描述.我搜索了很多例子,但没有人发布如何在视图页面上填充描述.这是我的代码:
视图模型:
public enum SearchBy
{
[Description("SID/PID")]
SID = 1,
[Description("Name")]
Name,
[Description("Birth Date")]
DOB,
[Description("Cause#")]
Cause
}
Run Code Online (Sandbox Code Playgroud)
Index.cshtml
<div class="form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group form-inline">
@Html.LabelFor(model => model.searchBy, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EnumDropDownListFor(model => model.searchBy, "Search By", htmlAttributes: new { @class = "form-control" })
@Html.TextBox("searchByVal", null, htmlAttributes: new { @placeholder = "SID / PID ", @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.FirstName, …Run Code Online (Sandbox Code Playgroud)