DropDownListFor does not select value if in for loop

后端 未结 6 1159
你的背包
你的背包 2020-12-05 17:49

In my view

<%= Html.DropDownListFor( x => x.Countries[ i ], Model.CountryList )%>

in my controller

public int[ ] C         


        
6条回答
  •  青春惊慌失措
    2020-12-05 18:33

    This is a bit of a hack, and JavaScript reliant but it worked very well for me.

    You'll need to know the client IDs that will be produced by the fields (usually these can be worked out manually but for safety you may want to use something like a FieldIDFor method.

    You just need to set the values based on the model, in jQuery's $(document).ready:

    
    

提交回复
热议问题