当我试图返回的实体JSON和我不断收到此错误:错误返回实体JSON
的ObjectContext的实例已经设置,不能再用于需要连接的操作。
这里是我的代码:
public JsonResult ListAllDepartments()
{
JsonResult jsonResult = null;
using (var db = new EventTrackerDB())
{
var foundDepartments = from departments in db.EVNTTRKR_Departments
select departments;
jsonResult = Json(foundDepartments.ToList(), JsonRequestBehavior.AllowGet);
}
return jsonResult;
}
我不明白为什么错误发生。我在结果集上调用了toList()。
如果我去myapp/Departments/ListAllDepartments,我收到错误消息。
有没有人知道这个解决方案?
谢谢!
尝试'var foundDepartments = db.EVNTTRKR_Departments..ToList(); jsonResult = Json(foundDepartments,JsonRequestBehavior.AllowGet);' – user2031802