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)

0

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

1 Comment

it's not working in my project.. I'm having the same results..NotSubmitted, RepeatRequest...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.