Html.DropDownList Selected Value Not Working (Using Constructor with IEnumerable)

后端 未结 8 2037
盖世英雄少女心
盖世英雄少女心 2021-02-18 19:02

I have an issue where the selected value is not working for the Html.DropDownList helper method. See below:

This is My Controller:

public ActionResult Ed         


        
8条回答
  •  一向
    一向 (楼主)
    2021-02-18 19:09

    First of all, how do you populate ViewBag.NewsItemId.Items ? We don't see where the values come from.

    In order to make a selected value work, it must be of the same type as the elements of your collections. If item.NewsItemId is of type T, ViewBag.NewsItemId.Items must be of type IEnumerable (or any other collection type implementing it). It does not seem to be the case, because you set NewsItemId as the selected value while your collection is based on NewsItemId.Items which may not be of the same type.

提交回复
热议问题