The ViewData item that has the key 'GenderID' is of type 'System.Int32' but must be of type 'IEnumerable'

前端 未结 2 465
梦毁少年i
梦毁少年i 2021-01-24 22:18

The error occurs when i tried to Submit/Post the data... could someone please help i tried every post but they are not helping me. I am new to mvc... any help will be granted he

2条回答
  •  春和景丽
    2021-01-24 22:50

    The error means that the value of Model.Gender is null (and as a result the DropDownListFor() method expects that the first parameter is IEnumerable.

    In your case, when you submit the form and ModelState is invalid, you return the view and have not assigned a value to Model.Gender (hence it is null and the excption is thrown.

    Ensure that you re-assign the value of Model.Gender in the POST method (just as you did in the GET method) before you return the view.

提交回复
热议问题