在我的控制,我有:的DropDownList和ViewData的
Category x = new Category(1, "one", 0);
Category y = new Category(2, "two", 1);
Category z = new Category(3, "three", 1);
List<Category> categories = new List<Category>();
categories.Add(x);
categories.Add(y);
categories.Add(z);
ViewData["categories"] = categories;
在我看来,我有:
<%= Html.DropDownList("categories")%>
但我有一个错误:具有关键“类别”的ViewData的产品类型'System.Collections.Generic.List`1 [[Category,MvcApplication1,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null]]',但必须是'IEnumerable'类型。
uggggghhh该如何解决?
我的教程解释此http ://www.asp.net/mvc/tutorials/javascript/working-with-the-dropdownlist-box-and-jquery/using-the-dropdownlist-helper-with-aspnet-mvc http://blogs.msdn .com/b/rickandy/archive/2012/01/09/cascasding-dropdownlist-in-asp-net-mvc.aspx – RickAndMSFT 2012-04-09 02:36:28