繁体   English   中英

名为Color的Enum的EditorFor不使用编辑器模板

[英]EditorFor with Enum named Color not using editor template

我有一个名为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之外的所有属性, 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")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM