public class ViewModelTables : IEnumerable , IEnumerator
{
public List<Order> orderList = new List<Order>();
}
I have created my own class to strongly type my view. How do I use the genericList of table Order to achieve my task?
public class HomeController : Controller
{
public ActionResult Index()
{
DataClasses1DataContext dc = new DataClasses1DataContext();
var my2Tab = new ViewModelTables();
//my2Tab.customer = (from m in dc.Customers
// where m.CustomerID == "ALFKI"
// select m).First();
var list = (from m in dc.Orders
where m.CustomerID == "ALFKI"
select m).ToList();
foreach (var v in list)
{
my2Tab.orderList.Add(v);
}
return View(my2Tab);
}
public ActionResult About()
{
return View();
}
}
The model item passed into the dictionary is of type ‘MvcApplication1.Models.ViewModelTables’, but this dictionary requires a model item of type ‘System.Collections.Generic.IEnumerable`1[MvcApplication1.Models.ViewModelTables]’.
Assuming your view is defined to accept the viewmodel like this:
Then I would remove the
IEnumerableandIEnumeratorfrom theViewModelTablesclass unless you have a specific reason why they are on the class definition.