MVC - Set selected value of SelectList

后端 未结 14 1220
后悔当初
后悔当初 2020-12-13 08:03

How can I set the selectedvalue property of a SelectList after it was instantiated without a selectedvalue;

SelectList selectList = new SelectList(items, \"I         


        
14条回答
  •  孤街浪徒
    2020-12-13 08:44

    Further to @Womp answer, it's worth noting that the "Where" Can be dropped, and the predicate can be put into the "First" call directly, like this:

    list.First(x => x.Value == "selectedValue").Selected = true;

提交回复
热议问题