绑定下拉? [英] bind drop down?

查看:121
本文介绍了绑定下拉?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在aspx页面中,我收到此错误,而绑定下拉列表


无法投射类型
'系统的对象.Web.Mvc.SelectList'键入
'System.Collections.Generic.IList`1 [System.Web.Mvc.SelectListItem]'。


我写过:

 < p> 
< label for =categoryId>类别:< / label>
<%= Html.DropDownList(categoryId,(IList< SelectListItem>)ViewData [categoryId])%>
<%= Html.ValidationMessage(categoryId,*)%>
< / p>

请告诉我正确的写作方式。



谢谢



ritz

解决方案

这是一个很好的例子正是您正在尝试完成的任务:



如何绑定IList与MVC Dropdownlist框



看起来你将不得不添加一些代码隐藏代码来构建兼容的列表类型。 >

in the aspx page i am getting this error while binding dropdown list

Unable to cast object of type 'System.Web.Mvc.SelectList' to type 'System.Collections.Generic.IList`1[System.Web.Mvc.SelectListItem]'.

I have written:

<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.

thanks

ritz

解决方案

Here is a nice example of exactly what you are trying to accomplish:

How to bind IList with MVC Dropdownlist box

It looks like you will have to add some code-behind code to build the compatible list type.

这篇关于绑定下拉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆