- ASP.NET MVC DropDownListFor或DropDownList 不能设置默认选项
关键点在于ViewBag.XX不能与字段名同名。否则无法设置默认值。应该是因为冲突。
例如:
@Html.DropDownListFor(model => model.dept_id, ViewBag.depts as IEnumerable<SelectListItem>,string.Empty, new { style = "width:180px" })
不能写成:
@Html.DropDownListFor(model => model.dept_id,ViewBag.dept_id as IEnumerable<SelectListItem>,string.Empty, new { style = "width:180px" })