0

Could you please advice me on what this error means:

The ViewData item that has the key "Cat ID" is of type'System.Int32' but must be of type IEnumerble

I'm using entity framework

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
HimWell
  • 11
  • 7
  • 3
    the error is specific to asp.net mvc, please post the relevant code – Ehsan Sajjad Oct 26 '17 at 11:07
  • Check the message. It says that you tried to tread `Cat ID` as if it were an array or list – Panagiotis Kanavos Oct 26 '17 at 11:09
  • You've just passed one item into your `ViewData` and used it in the view with `foreach`, it should be a `IEnumerable` collection. #Sherlock – SᴇM Oct 26 '17 at 11:10
  • 1
    We need codes to understand your problem – GGO Oct 26 '17 at 11:10
  • 1
    What I have difficulty understanding is, why people take the burden of writing the error messages by hand instead of copying / pasting it. In the above error message, there are two obvious typos. Cases where the source code is re-written by hand is also not that rare. Why? – Oguz Ozgul Oct 26 '17 at 11:43

1 Answers1

0

You've just passed one item into your ViewData.In your case Viewdata has got list of items, so you should cast ViewData as a IEnumerable and then get the values from foreach loop.