Anup
Anup

Reputation: 9738

MVC - Exclude from Enum

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" })

Upvotes: 1

Views: 1690

Answers (1)

Selman Genç
Selman Genç

Reputation: 101681

You can use Where

Enum.GetNames(typeof(Models.EmployeeStatus)).Where(x => x != "NA")

Upvotes: 6

Related Questions