tags:

views:

57

answers:

1

Hello, I have this line of code in my view but it doesn't work. It keep throwing this error:

The ViewData item that has the key 'Material.Modelo.Categoria.Familia_Id' is of type 'System.Int32' but must be of type 'IEnumerable'

<%= Html.DropDownListFor(model => model.Material.Modelo.Categoria.Familia_Id, Model.Familias, " -- Seleccione -- ")%>

Model.Familias is actually a seleclist and model.Material.Modelo.Categoria.Familia_Id is an integer.

Any ideas?

Thnx

A: 

Html.DropDownListFor expects to be passed a collection (something that imlements IEnumberable) so that it can build a drop down of these items.

You're passing it a single integer.

Assuming you have a drop down with just one item in it then add that integer to a collection of some sort and pass the collection. A List, or any other collection implementing IEnumerable, will work fine.

Check out this post...

http://stackoverflow.com/questions/1297399/populating-asp-net-mvc-dropdownlist

... for details on how to populate one of these.

Martin Peck
The first Param in DropDownListFor is the property in the model you want to send back to the controller that is selected, the SECOND one is the IEnumerable collection. It looks to me like she is doing it right.
Climber104
Exactly... and actually I have this: <%= Html.DropDownListFor(model => model.Material.Modelo_Id, Model.Modelos," -- Seleccione -- ") %> and that works fine. So, what may be happening?
tina
Notice the use of SelectList in the answer that I refer to. I think that's the difference.
Martin Peck