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