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

后端 未结 9 1754
日久生厌
日久生厌 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:43

    I got same error today and my solution is to make model "valid".

    In my case, after user submit by clicking "save", I got model state: invalid if user key-in "0", but model state will be valid if user key-in "0.0".

    So I override "IsValid" method to return true even user key-in "0".

    Hope it helps.

提交回复
热议问题