1

I have an enum which is used in dropdown for selection. I don't want to show 1st enum which is NA in my dropdown.

How to exclude 1 element from enum?

public enum EmployeeStatus
    {
        NA = 1,
        Active = 2,
        InActive = 3,
        Other = 5
    }

@Html.DropDownListFor(model => model.EmployeeStatus, Enum.GetNames(typeof(Models.EmployeeStatus)).Select(e => new SelectListItem { Text = e }), "--Select Type--", new { @class = "form-control" })

1 Answer 1

6

You can use Where

Enum.GetNames(typeof(Models.EmployeeStatus)).Where(x => x != "NA")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.