There were many related questions, but none solved my matter. My purpose here is generating a pdf using Razor PDF. So I have a controller action, which contains;
var pdf = new PdfResult(null, "myView");
ViewBag.VrList = MyDbQuery.GetExpiredVL(DateTime.Today);
return pdf;
MyDbQuery is in a different solution which I'm using. And there I have this method:
public static List<VLEntity> GetExpiredVL(DateTime ReportDate)
{
using (MyDbContext db = new MyDbContext())
{
return db.VLEntity.Where(vl => vl.ValidTo.Month == ReportDate.Month && vl.ValidTo.Year == ReportDate.Year).ToList();
}
}
My view looks like:
@foreach (var vrRow in ViewBag.VrList)
{
@vrRow.VEntity.VssId
}
When I debug, I get:
System.ObjectDisposedException: The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.
In similar questions i have found here says to use using
statement. But you can see here I have already used that. I'm very new to ASP.NET and C# altogether and I'll be grateful if you can come up with a solution for this.