ASP.NET MVC - Html.DropDownList - Value not set via ViewData.Model

前端 未结 7 1161
Happy的楠姐
Happy的楠姐 2020-12-14 09:24

Have just started playing with ASP.NET MVC and have stumbled over the following situation. It feels a lot like a bug but if its not, an explanation would be appreciated :)<

7条回答
  •  爱一瞬间的悲伤
    2020-12-14 10:12

    try setting the selected value in the controller action when creating the SelectList collection.

    ViewData["AddressTypeId"] = new SelectList(CustomerService.AddressType_List(), "AddressTypeId", "Name", myItem.AddressTypeId);

提交回复
热议问题