[英]EditorFor with Enum named Color not using editor template
I have a property named Color
of type Enum
named Color
, and I'm trying to use an editor template. 我有一个名为Color
的属性,类型为Enum
名为Color
,我正在尝试使用编辑器模板。 My enum editor template is: 我的枚举编辑器模板是:
@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>
This works for every property except Color
which gets rendered as: 这适用于除Color
之外的所有属性, 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)
works exactly as expected, but @Html.EditorFor(Function(model) model.Color)
results in the HTML color input above. @Html.EditorFor(Function(model) model.AnyOtherEnumProperty)
完全按预期工作,但是@Html.EditorFor(Function(model) model.Color)
导致上面的HTML颜色输入。 How can I get MVC to use the proper editor template? 如何使MVC使用正确的编辑器模板?
要变通解决此问题,手动指定编辑器模板的名称,如下所示:
@Html.EditorFor(Function(model) model.Color, "Enum")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.