モデル バインダーが編集モードのドロップダウン リストで機能しないのはなぜですか?
編集ビューで、このコードを記述し、2 つの異なる 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");
ただし、編集モードのすべてのテキストボックスはモデルバインダーで埋められますが、ドロップダウンリストでは発生しません。
- - - -アップデート - - - -
つまり、編集モードでは、モデルバインダーはデータベースからのすべてのデータをテキストボックスと各要素にバインドします...しかし、ドロップダウンリストでは、モデルバインダーはデータベースからのデータを選択された値としてドロップダウンリストにバインドしません