简体   繁体   English

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

[英]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.

相关问题 EditorFor ICollection并命名为Template - EditorFor ICollection and named Template 如何为布尔值创建编辑器模板? (.EditorFor &lt;&gt;) - How to create an Editor Template for Boolean? (.EditorFor<>) 在与EditorFor扩展方法一起使用时包装的编辑器模板 - Editor template being wrapped whilst being used with EditorFor extension method 如何通过 @Html.EditorFor 通过 ViewData 将值传递给编辑器模板 - How to pass value by ViewData to Editor Template by @Html.EditorFor 在不使用自定义编辑器模板的情况下使用MVC EditorFor时如何将type =“ datetime”更改为HTML5标准type =“ date”? - How to change type=“datetime” to HTML5 standard type=“date” when using MVC EditorFor without custom Editor Template? 动态编辑器用于使用模型中的模板 - Dynamic EditorFor using template from Model 使用EditorFor()而不是Editor()的EditorTemplates / Object.cshtml? - EditorTemplates/Object.cshtml using EditorFor() instead of Editor()? 枚举RadioButtonFor编辑器模板设置值 - Enum RadioButtonFor Editor Template set value 使用编辑模板而不使用Html.EditorFor() - Using a edit template without using Html.EditorFor() ASP.NET MVC:使用EditorFor()和枚举的默认模板 - ASP.NET MVC: Using EditorFor() with a default template for enums
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM