我有一个名为Color
的Enum
类型的名为Color
的属性,我正在尝试使用编辑器模板。我的枚举编辑器模板是:
@ModelType System.Enum
<div class="form-group">
@Html.LabelFor(Function(model) model)
@Html.EnumDropDownListFor(Function(model) model, New With {.Class = "form-control"})
@Html.ValidationMessageFor(Function(model) model, "", New With {.Class = "text-danger"})
</div>
这适用于除Color
之外的每个属性,它被渲染为:
<input class="text-box single-line valid"
data-val="true"
data-val-required="The Color field is required."
id="Color"
name="Color"
type="color"
value="Black"
aria-describedby="Color-error"
aria-invalid="false">
@Html.EditorFor(Function(model) model.AnyOtherEnumProperty)
完全按预期工作,但@Html.EditorFor(Function(model) model.Color)
导致上面的HTML颜色输入。如何让MVC使用正确的编辑器模板?
要解决此问题,请手动指定编辑器模板的名称,如下所示:
@Html.EditorFor(Function(model) model.Color, "Enum")