我asp-items="@Html.GetEnumSelectList(typeof(Salary))"在Razor视图中使用了一个select标签,根据它填充列表值enum Salary.
但是,我的枚举包含一些我希望在其中有空格的项目.例如,其中一个项目是PaidMonthly,但是当我使用它时Html.GetEnumSelectList,我希望它显示为"Paid Monthly"(其中有一个空格)
我尝试Description在枚举中使用每个成员的属性,但是当选择框呈现时它仅使用原始值.
谁有人可以帮我解决这个问题?
(我的代码示例) - >使用ASP.NET Core 1.0
剃刀查看:
<select asp-for="PersonSalary" asp-items="@Html.GetEnumSelectList(typeof(Enums.Salary))">
</select>
Run Code Online (Sandbox Code Playgroud)
Enum薪水:
public enum Salary
{
[Description("Paid Monthly")]
PaidMonthly = 1,
PaidYearly = 2
}
Run Code Online (Sandbox Code Playgroud)