【发布时间】:2023-03-23 03:51:01
【问题描述】:
我有这门课State:
public enum State
{
Ok,
[Display(Name = "Not Submitted")]
NotSubmited,
[Display(Name = "Repeat Request")]
RepeatRequest,
Sent,
Error,
Response
}
考虑到Display 属性是用户友好的,如何使用Display 属性在DropDownList 中显示enum 值?
我一直在尝试,但我总是得到原始值(NotSubmitted, RepeatRequest 没有空格..)
这是我的DropDownList 代码:
<select name="Response[@index].State" class="form-control">
<option value="">Select State</option>
@foreach (var state in Enum.GetValues(typeof(State)))
{
<option>@state</option>
}
</select>
还有:
var ValuesArray =Enum.GetValues(typeof(Status));
var NamesArray = Enum.GetNames(typeof(Status));
但仍然总是得到不友好的价值观...(例如NotSubmitted 而不是Not Submitted)
【问题讨论】:
标签: c# html asp.net-mvc drop-down-menu enums