http://q.cnblogs.com/q/73902/
项目使用mvc4,给dropDownList指定默认值未选中
页面代码是:
1、未有默认选中值
Html.DropDownListFor(m => m.Type, ViewData["Type"] as IEnumerable<SelectListItem>, new { @class = "form-control", disabled = "true" })
2、有默认选中值
@Html.DropDownList("Type")
请问第一种默认选中值如何实现?
Controller中代码是:
问题答案:
我也遇到这个问题了,困扰了我几个小时,现在解决了,用SelectList绑定,不要用IEnumable<SelectListItem>,,不知道微软为什么不修复这个问题
@{
var selectList = new SelectList(approverList, "Id", "FullName", Model.Approvers[i].Id);
}
@Html.DropDownListFor(m => m.Approvers[i].Id, selectList, "", new { @class = "form-control approver" })