我想从下面的结构中创建一个下拉列表
List<KeyValuePair<long, string>> sponsori =
new List<KeyValuePair<long, string>>();现在,如果我只能访问选定项的long值,那么我希望selectlist具有该对的long as数据值、字符串作为文本值和选定项。
提前使用THanks。
发布于 2010-03-18 22:26:33
在你的动作代码中
yourViewModel.Sponsori= new SelectList(sponsori, "Key", "Value")在你的视图代码中
<%=Html.DropDownList("yourSelectid", Model.Sponsori) %>发布于 2010-03-18 22:26:51
ViewData["selectList"] = new SelectList(sponsori, "Key", "Value");然后在页面上:
<%= Html.DropDownList("selectList") %>您还可以查看在ASP.NET MVC Using HTML Helpers中呈现表单的类似示例(以及更多文档)。
https://stackoverflow.com/questions/2470498
复制相似问题