【发布时间】:2013-08-13 14:29:40
【问题描述】:
public class DropDown
{
public string[] SelectedItems { get; set; }
public IEnumerable<SelectListItem> Items { get; set; }
}
我正在尝试从具有上述结构的 DB 中获取 MVC 中的 DropDown。
从数据库中,我得到了 Text 和 value 字段,并在 IEnumerable<T> 中拥有 T 有 2 个属性 id 和 text。
将 ienumerable id 转换为字符串数组并将 id、文本分配给 SelectedListItem 的最佳方法是什么?
我想过循环遍历 ienumerable 并形成 DropDown,但认为会有更好的方法。
更新
例如:
In DB i have student table with
ID,
Name,
Class,
Section
我在 ienumerable<student> 中获得了 id 和 Name。从那里我需要转换成DropDown
【问题讨论】:
标签: asp.net-mvc