I have a loop in razor which generates a template a number of times. Inside the template there is a dropdownlist
@Html.DropDownlistFor(x=>x.pasajero[i].option, Model.optionItems)
The dropdownlist is rendered, however no option is set with the selected="selected"
attribute.
I have been able to properly render the dropdownlist outside a loop using same values. Any ideas why?
Try:
@Html.DropDownlistFor(x => x.pasajero[i].option,new SelectList(Model.optionItems,"IdField","DisplayField", Model.pasajero[i].option))
Make sure x.pasajero[i].option
has the same type as IdField
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With