从数据库中选择时MVC打开DataReader错误

时间:2016-12-09 23:36:55

标签: asp.net-mvc entity-framework asp.net-mvc-5

当我尝试通过从数据库中选择来填充变量时,我收到以下错误:

  

“已经有一个与此命令关联的打开DataReader   必须先关闭。“

            //Admin Venue Partial View
            public ActionResult AdminVenuesTablePartialView()
            {
                VenueTownViewModel vt = new VenueTownViewModel();
                List<VenueTownViewModel> model = new List<VenueTownViewModel>();

                foreach (var venue in db.Venues)
                {
                    vt.VenueID = venue.VenueID;
                    vt.VenueName = venue.VenueName;
                    vt.VenueTown = db.Towns.Find(venue.TownID).Town;
                    vt.VenueActive = venue.VenueActive;

                    model.Add(vt);                
                }

                return PartialView("_AdminVenues", model.OrderBy(v => v.VenueName).ToList());
            }

0 个答案:

没有答案