MVC - 从Enum中排除

时间:2014-10-15 12:24:25

标签: c# asp.net-mvc razor enums

我有enumdropdown用于选择。我不想在1st enum中显示NA dropdown

如何exclude来自enum的1个元素?

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 个答案:

答案 0 :(得分:6)

您可以使用Where

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