-1

モデル バインダーが編集モードのドロップダウン リストで機能しないのはなぜですか?

編集ビューで、このコードを記述し、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");

ただし、編集モードのすべてのテキストボックスはモデルバインダーで埋められますが、ドロップダウンリストでは発生しません。

なぜ ? ここに画像の説明を入力

- - - -アップデート - - - -

つまり、編集モードでは、モデルバインダーはデータベースからのすべてのデータをテキストボックスと各要素にバインドします...しかし、ドロップダウンリストでは、モデルバインダーはデータベースからのデータを選択された値としてドロップダウンリストにバインドしません

4

2 に答える 2