【发布时间】:2014-03-07 21:42:58
【问题描述】:
我有这些枚举
public enum QuestionStart
{
[Display(Name="Repeat till common match is found")]
RepeatTillCommonIsFound,
[Display(Name="Repeat once")]
RepeatOnce,
[Display(Name="No repeat")]
NoRepeat
}
public enum QuestionEnd
{
[Display(Name="Cancel Invitation")]
CancelInvitation,
[Display(Name="Plan with participants on first available common date")]
FirstAvailableCommon,
[Display(Name="Plan with participants on my first available common date")]
YourFirstAvailableCommon
}
我有一个帮助类来显示枚举中每个字段的所有单选按钮
@model Enum
@foreach (var value in Enum.GetValues(Model.GetType()))
{
@Html.RadioButtonFor(m => m, value)
@Html.Label(value.ToString())
<br/>
}
现在标签设置为值名称,而不是我为值指定的显示名称。
例如:
[Display(Name="Cancel Invitation")]
CancelInvitation
我得到带有CancelInvitation 的单选按钮。
如何让它显示我给它的显示名称(Cancel Invitation)?
【问题讨论】:
-
@Biploav13,试试这个解决方案,让我知道结果 - stackoverflow.com/questions/9328972/…
-
代码是否适用于 MVC5 ?
-
我应该在哪里实现该功能?我的视图使用 Html.EditorFor 并且我有帮助类来显示单选按钮。
-
我将标签更改为更特定于版本:MVC4 似乎无法很好地处理将
dynamic提供给RadioButtonFor的问题 -
我想我更新到 mvc 5.1 但我该如何检查?
标签: c# asp.net-mvc enums asp.net-mvc-5