How to set the selected value in EnumDropDownListFor?

后端 未结 3 1118
春和景丽
春和景丽 2020-12-19 02:31

I\'m using MVC 5.2.0 and I\'m trying to use the new Html.EnumDropDownListFor. This is how I\'m setting the values:

//Model
public class MyModel          


        
3条回答
  •  遥遥无期
    2020-12-19 03:05

    Just Use This in Your Controller, It works like a charm

    MyModel.TestEnum = (TestEnum)SelectedEnumId;
    

    Not This will work fine assuming the case, that SelectedEnumId > 0.

    if(SelectedEnumId > 0) {
       MyModel.TestEnum = (TestEnum)SelectedEnumId;
    }
    

提交回复
热议问题