Some times you end up with this error in MVC saying "
The ViewData item that has the key ''is of
type 'System.Int32' but must be of type 'IEnumerable<SelectListItem>'."
There are 2 possible reasons that this could happen.
One is that if you have a view where you are displaying a dropdownlist but you are not returning a list to it and it tries to read the Id value from your entity and it says that it is expecting a list and what you returning is not a list.
So probably you resend the data by converting to .ToList()
Second scenario would be you have do a create operation and forget it to redirect to index page and being in the same page again and if you don't fill your view bag again with that dropdownlist value that you populating then it would throw that error back.
No comments:
Post a Comment