我有这个课程State
:
public enum State
{
Ok,
[Display(Name = "Not Submitted")]
NotSubmited,
[Display(Name = "Repeat Request")]
RepeatRequest,
Sent,
Error,
Response
}
考虑到DropDownList
属性是否用户友好,如何使用enum
属性显示Display
Display
个值?
我一直在尝试,但我总是得到原始值(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
)
答案 0 :(得分:0)
<select name="Response[@index].State" class="form-control">
<option value="">Select State</option>
@foreach (var state in Enum.GetValues(typeof(State)))
{
<option>Enum.GetName(typeof(State), state )</option>
}
</select>