The ViewData item that has the key 'MY KEY' is of type 'System.String' but must be of type 'IEnumerable'

后端 未结 9 1753
日久生厌
日久生厌 2020-11-28 03:02

I am trying to populate a dropdown list from a database mapped with Linq-2-SQL, using ASP.NET MVC 2, and keep getting this error.

I am so confused because I am decla

9条回答
  •  迷失自我
    2020-11-28 03:52

    If you use Html.DropDownList() method - same error may occur, if your ViewData/Viewbag item not set, as @Peto answered.

    But it may be not set in case of controller set item correctly, but in main view you use partial viw call with new ViewDataDictionary values.

    if you have @Html.Partial("Partianame", Model,new ViewDataDictionary() { /* ... */ }) then your partial view will not see ViewData and ViewBag data, remove new ViewDataDictionary() parameter

提交回复
热议问题