DropDownListFor Not Selecting Value

后端 未结 11 1148
醉梦人生
醉梦人生 2020-11-29 18:14

I\'m using the DropDownListFor helper method inside of an edit page and I\'m not having any luck getting it to select the value that I specify. I noticed a similar question

11条回答
  •  旧巷少年郎
    2020-11-29 19:03

    While not addressing this question - it may help future googlers if they followed my thought path:

    I wanted a multiple select and this attribute hack on DropDownListFor wasn't auto selecting

    Html.DropDownListFor(m => m.TrainingLevelSelected, Model.TrainingLevelSelectListItems, new {multiple= "multiple" })
    

    instead I should have been using ListBoxFor which made everything work

    Html.ListBoxFor(m => m.TrainingLevelSelected, Model.TrainingLevelSelectListItems)
    

提交回复
热议问题