使用MVC3我在我的控制器中有这个。如何在视图中枚举这个?
public ActionResult NWaySwitch()
{
var switches = _nWaySwitch.Switches.Cast<Switch>().ToList();
// var switches = _nWaySwitch.Switches;
return View(switches);
}
foreach语句不能对'object'类型的变量进行操作,因为'object'不包含'GetEnumerator'的公共定义
@foreach(ViewData中的System.Collections.ArrayList项目[“switches”]) {}
答案 0 :(得分:3)
我猜你在这里做了一个强类型的视图吗?如果查看视图的顶部,您可能会看到模型定义。确保在IEnumerable&lt;&gt;中进行此操作你应该好好去