EditorFor与枚举名为Color不使用编辑器模板

问题描述 投票:0回答:1

我有一个名为ColorEnum类型的名为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使用正确的编辑器模板?

asp.net-mvc vb.net razor asp.net-mvc-5 mvc-editor-templates
1个回答
0
投票

要解决此问题,请手动指定编辑器模板的名称,如下所示:

@Html.EditorFor(Function(model) model.Color, "Enum")
© www.soinside.com 2019 - 2024. All rights reserved.