如何在 Razor 的下拉列表中显示我的枚举的自定义名称?我目前的代码是:
@Html.DropDownListFor(model => model.ExpiryStage,
new SelectList(Enum.GetValues(typeof(ExpiryStages))),
new { @class = "selectpicker" })
我的枚举是:
public enum ExpiryStages
{
[Display(Name = "None")]
None = 0,
[Display(Name = "Expires on")]
ExpiresOn = 1,
[Display(Name = "Expires between")]
ExpiresBetween = 2,
[Display(Name = "Expires after")]
ExpiresAfter = 3,
[Display(Name = "Current")]
Current = 4,
[Display(Name = "Expired not yet replaced")]
ExpiredNotYetReplaced = 5,
[Display(Name = "Replaced")]
Replaced = 6
}
例如,我想在 DropDownList 中显示“Expired NotYetReplaced”而不是 ExpiredNotYetReplaced。