DropDownListFor does not select value if in for loop

后端 未结 6 1151
你的背包
你的背包 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:22

    Instead of using a IEnumerable in your viewmodel use a List of objects like this one:

    public List> TiposValorCobertura { get; private set; }
    

    And in your view when you assign the selectable elements for the dropdownlist in the loop, do it this way:

    @Html.DropDownListFor(m => m.Coberturas[i].TipoLimiteInferior, new SelectList(Model.TiposValorCobertura,"Key","Description",  Model.Coberturas[i].TipoLimiteIferior))
    

    Where "Key" and "Description" are PairVM's properties

提交回复
热议问题