MVC looping in razor, generated dropdownlist not v

2019-06-19 02:32发布

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?

1条回答
来,给爷笑一个
2楼-- · 2019-06-19 02:55

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.

查看更多
登录 后发表回答