我有这个填充ASP.NET MVC视图中的下拉列表.
<%= Html.DropDownListFor(model => model.Bikes,
Model.Bikes.Select(
x => new SelectListItem {
Text = x.Name,
Value = Url.Action("Details", "Bike", new { bikeId = x.ID }),
Selected = x.ID == Model.ID,
})) %>
Run Code Online (Sandbox Code Playgroud)
调试这个我可以看到该Selected属性设置为true应该的时间.但是,在呈现视图时,列表中的所有选项都未被选中.我意识到这可以通过另一个重载完成,DropDownListFor但我真的想让这个版本工作.
有任何想法吗?