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" })
