DropDownList and ViewData

Posted by Petko Xyz on Stack Overflow See other posts from Stack Overflow or by Petko Xyz
Published on 2012-04-08T17:18:45Z Indexed on 2012/04/08 17:30 UTC
Read the original article Hit count: 128

Filed under:

In my controller I have:

        Category x = new Category(1, "prva", 0);
        Category y = new Category(2, "vtora", 1);
        Category z = new Category(3, "treta", 1);
        List<Category> categories = new List<Category>();
        categories.Add(x);
        categories.Add(y);
        categories.Add(z);
        ViewData["categories"] = categories;

And in my view I have:

    <%= Html.DropDownList("categories")%>

But I have an error: The ViewData item that has the key 'categories' is of type 'System.Collections.Generic.List`1[[Category, MvcApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' but must be of type 'IEnumerable'.

Uggggghhh how to resolve this?

© Stack Overflow or respective owner

Related posts about asp.net-mvc