【发布时间】:2015-07-15 21:13:50
【问题描述】:
我一直在使用这个编辑器模板进行枚举:
@model Enum
@{
var htmlAttributesFromView = ViewData["htmlAttributes"] ?? new { };
var htmlAttributes = Html.MergeHtmlAttributes(htmlAttributesFromView, new { @class = "form-control" });
}
<div class="form-group">
@Html.LabelFor(model => model, htmlAttributes: new { @class = "control-label col-md-3" })
<div class="col-md-8">
@Html.EnumDropDownListFor(x => x, htmlAttributes)
@Html.ValidationMessageFor(model => model)
</div>
<a class="infoonclick col-md-1" title="@Html.DisplayNameFor(model => model)" data-content="@Html.DescriptionFor(model => model)">
<span class="fa fa-info-circle"></span>
</a>
</div>
EnumDropDownListFor() 给了我这样的东西:
<option value="0">blah0</option>
<option value="1">blah1</option>
我想创建一个对值和文本都使用枚举文本(或显示名称)的版本。
<option value="blah0">blah0</option>
<option value="blah1">blah1</option>
我找到了一种方法来使用键入到特定枚举的模板,但如果可能的话,我想对所有枚举进行通用操作。
【问题讨论】:
标签: asp.net-mvc enums mvc-editor-templates