绑定下拉? [英] bind drop down?
问题描述
在aspx页面我得到这个错误,而绑定下拉列表
in the aspx page i am getting this error while binding dropdown list
无法投类型的对象
System.Web.Mvc.SelectList到类型
System.Collections.Generic.IList`1 [System.Web.Mvc.SelectListItem]'。
Unable to cast object of type 'System.Web.Mvc.SelectList' to type 'System.Collections.Generic.IList`1[System.Web.Mvc.SelectListItem]'.
我已经写:
<p>
<label for="categoryId">Category:</label>
<%= Html.DropDownList("categoryId", (IList<SelectListItem>)ViewData["categoryId"])%>
<%= Html.ValidationMessage("categoryId", "*")%>
</p>
请告诉我,写的正确途径。
please tell me the correct way of writing.
感谢
丽思
推荐答案
下面是你要完成的正是一个很好的例子:
Here is a nice example of exactly what you are trying to accomplish:
<一个href=\"http://www.altafkhatri.com/Technical/How%5Fto%5Fbind%5FIList%5Fwith%5FMVC%5FDropdownlist%5Fbox\"相对=nofollow>如何使用MVC DROPDOWNLIST箱绑定的IList
看起来你将不得不增加一些code-背后code构建兼容列表类型。
It looks like you will have to add some code-behind code to build the compatible list type.
这篇关于绑定下拉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!