Tuesday, 24 October 2017

MVC - Fix error - The result of a query cannot be enumerated more than once

 Watch this example on YouTube



to fix it convert function that loads view
replace
        public ActionResult Test()
        {
            OrderClass model = new OrderClass();
            model.or = db.SelectOrders().FirstOrDefault();
            model.pr = db.SelectProducts();
            return View(model);
        }

with
        public ActionResult Test()
        {
            OrderClass model = new OrderClass();
            model.or = db.SelectOrders().FirstOrDefault();
            model.pr = db.SelectProducts().ToList();
            return View(model);
        }

No comments:

Post a Comment