MVC view and enumerate a list
Using MVC3 I have this in my controller. How do I enumerate this within the view?
public ActionResult NWaySwitch()
{
var switches = _nWaySwitch.Switches.Cast<Switch>().ToList();
// var switches = _nWaySwitch.Switches;
return View(switches);
}
开发者_Go百科foreach statement cannot operate on variables of type 'object' because 'object' does not contain a public definition for 'GetEnumerator'
@foreach (System.Collections.ArrayList item in ViewData["switches"]) {}
I am guessing you made a strongly typed view here right? If you look at the top of the view you will probably see the Model definition. Make sure that you make this in a IEnumerable<> and you should be good to go
精彩评论