I want to show Enum
in EditorFor. I use Editor Template for show it.(DropDownList).
I have malty EditorFor
in view. I want to set class for some controls.
@Html.EditorFor(m => m.Position, new { @class = "smallinput", style = "width:150px !important" })
@Html.EditorFor(m => m.DocumentType)
In Editor: Views/Shared/DisplayTemplates/Enum.cshtml
@model Enum
@{
var values = Enum.GetValues(ViewData.ModelMetadata.ModelType).Cast<object>()
.Select(v => new SelectListItem
{
Selected = v.Equals(Model),
Text = v.GetDisplayName(),
Value = v.ToString()
});
}
@Html.DropDownList("", values)
In Model
[DisplayName("??? ???")]
[UIHint("Enum")]
public DocumentType DocumentType { get; set; }
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…