【发布时间】:2010-06-09 18:43:08
【问题描述】:
我正在尝试使用从属性中提取的值填充 DropDownList,而我现在的最终结果是一个只有“System.Web.Mvc.SelectListItem”的列表。我确定我在这里省略了一些小步骤,但对于我的生活,我无法弄清楚它是什么。
生成列表的属性 GET:
public IEnumerable<SelectListItem> AllFoo {
get {
var foo = from g in Bar
orderby g.name
select new SelectListItem {
Value = g.fooid.ToString(),
Text = g.name
};
return foo.AsEnumerable();
}
}
控制器代码:
public ActionResult Edit(string id) {
// n/a code
ViewData["fooList"] = new SelectList(g.AllFoo, g.fooid);
return View(g);
}
查看代码:
<%= Html.DropDownListFor(model => model.fooid, ViewData["fooList"] as SelectList) %>
【问题讨论】:
标签: c# asp.net-mvc linq-to-sql