Suppose we have some enum type in c# as follows :
enum Performance
{
None=-1,
Dissatisfied=0,
Below Average=1,
Average =2,
Good = 3,
Excellent=4,
}
Consider some employee model with a given enum type property.
public class EmployeePerformance{
public int EmpId {get; set;}
public Performance rating{get; set}
…………………………..
………………………..
}
In a model-binded view, we can populate the dropdown items from the enum on the .cshtml page as follows:
@Html.DropDownListFor(model => model.rating, new SelectList(Enum.GetValues(typeof(
Suppose you want to exclude items from the list of items in a dropdown list populated from Enum object,
Following is an example in which enum item with value -1 is removed-
@Html.DropDownListFor(model => model.rating, new SelectList(Enum.GetValues(typeof(