我正在编辑页面内使用 DropDownListFor 助手方法,但是我没有任何运气让它选择我指定的值。我注意到 Stackoverflow 上有个 类似的问题。建议的解决方案是“在视图代码中填充 SelectList”。问题是我已经试过了,还是没用。
<%= Html.DropDownListFor(model => model.States, new SelectList(Model.States.OrderBy(s => s.StateAbbr), "StateAbbr", "StateName", Model.AddressStateAbbr), "-- Select State --")%>
I have set a breakpoint and have verified the existence (and validity) of model.AddressStateAbbr. I'm just not sure what I'm missing.