How to keep dropdownlist selected value after postback

后端 未结 6 1178
日久生厌
日久生厌 2020-12-19 13:03

In asp.net mvc3 how to keep dropdown list selected item after postback.

6条回答
  •  北海茫月
    2020-12-19 13:19

    Assuming the selected item is part of the post, the controller now knows what it is. Simply have an entry in the ViewData dictionary indicating which item should be selected (null on get or if nothing was selected). In the view, check the value and if it's not null, select the appropriate option.

提交回复
热议问题