爲什麼模型綁定器在編輯模式的下拉列表中不起作用?asp.net mvc模型綁定器在編輯模式下不能用於下拉列表
在編輯視圖我寫這篇文章的代碼和測試兩種不同的DDL:
@Html.DropDownList("ProductParentCategoryId", null, htmlAttributes: new { @class = "form-control" })
@Html.DropDownListFor(model => model.ProductParentCategoryId, (SelectList)ViewBag.ParentId)
,並在我的控制器
ViewBag.ProductParentCategoryId = new SelectList(_productCategoryService.GetAllProductCategory(), "ProductCategoryId", "ProductCategoryTitle");
ViewBag.ParentId = new SelectList(_productCategoryService.GetAllProductCategory(), "ProductCategoryId", "ProductCategoryTitle");
但在編輯模式下,所有的文本框填充模型綁定,但不會發生了下降下拉列表。
------- -------更新
我的意思是在編輯模式下,模型綁定綁定從數據庫中的所有文本數據和各元素... 但在下拉列表模型綁定不從數據庫選定值將數據綁定到下拉列表