Exclude/Remove Value from MVC 5.1 EnumDropDownListFor

前端 未结 5 1707
隐瞒了意图╮
隐瞒了意图╮ 2020-12-13 06:01

I have a list of enums that I am using for a user management page. I\'m using the new HtmlHelper in MVC 5.1 that allows me to create a dropdown list for Enum values. I now h

5条回答
  •  感情败类
    2020-12-13 06:43

    You could construct a drop down list:

    @{ // you can put the following in a back-end method and pass through ViewBag
       var selectList = Enum.GetValues(typeof(UserStatus))
                            .Cast()
                            .Where(e => e != UserStatus.Pending)
                            .Select(e => new SelectListItem 
                                { 
                                    Value = ((int)e).ToString(),
                                    Text = e.ToString()
                                });
    }
    @Html.DropDownListFor(m => m.Status, selectList)
    

提交回复
热议问题