i am using ASP.NET MVC and EF and in my controller i am using something like this:
public ActionResult Index()
{
using (MyEntities db = new MyEntities())
{
var _info = db.INFORMATION;
return View(_info);
}
}
and it throws me the below error. (if i use using statements )
error:
The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.
and in my VIEW i am calling like this:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MVC_EF_Model.INFORMATION>" %>
<% foreach (var item in Model) { %>
<tr>...........
..............
You need to enumerate your collection before to pass it to your view. Something like this:
Indeed you are using an using so your datacontext does not exist anymore when performing the request that loads the infos entities. So you need to indicates it to perform this request before it is disposed.