0

I have this class State:

public enum State
    {
        Ok,
        [Display(Name = "Not Submitted")]     
        NotSubmited,
        [Display(Name = "Repeat Request")]
        RepeatRequest,
        Sent,
        Error,
        Response
    }

How can I display in a DropDownList the enum values making use of the Display attributes, considering that the Display attributes are user friendly? I've been trying but I always get the raw values(NotSubmitted, RepeatRequest without space..)

This is my code for the 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>

And:

var ValuesArray =Enum.GetValues(typeof(Status));
var NamesArray = Enum.GetNames(typeof(Status));

But still getting always the not friendly values...(NotSubmitted instead of Not Submitted for example)

AlexGH
  • 2,735
  • 5
  • 43
  • 76

1 Answers1

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>
shady youssery
  • 430
  • 2
  • 17
  • it's not working in my project.. I'm having the same results..`NotSubmitted`, `RepeatRequest`... – AlexGH Jul 31 '17 at 15:12