How to set the selected value in EnumDropDownListFor?

后端 未结 3 1116
春和景丽
春和景丽 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 02:49

    As far as I know just make sure the value you want to be selected is set in your Model before you call

    //Controller:
    ...
    myModel.TestEnum = TestEnum.name2;
    ...
    
    //On your view
    ...
    @Html.EnumDropDownListFor(model => model.TestEnum);
    ...
    

提交回复
热议问题