在前臺添加和編輯頁面中使用 @Html.DropDownListFor(model => model.xxx, (IEnumerable<SelectListItem>)ViewBag.dropDownList)時,如果表單中有必填項沒有填,就會報錯。
一直沒有解決,後面看到了前輩的博客,原來是每次檢查返回沒有重新返回dropdownlist中的內容。
只要在每次判斷返回頁面前重新給dropdownlist添加上內容就可以了。
在前臺添加和編輯頁面中使用 @Html.DropDownListFor(model => model.xxx, (IEnumerable<SelectListItem>)ViewBag.dropDownList)時,如果表單中有必填項沒有填,就會報錯。
一直沒有解決,後面看到了前輩的博客,原來是每次檢查返回沒有重新返回dropdownlist中的內容。
只要在每次判斷返回頁面前重新給dropdownlist添加上內容就可以了。