用MVC+EF做简单查询时,返回json格式数据出现问题
原代码: public ActionResult JSon({ NorthwindEntities db = new NorthwindEntities(); Employees per = db.Employees.Where(u => u.EmployeeID == 1).FirstOrDefault(); return Json(per, JsonRequestBehavior.AllowGet); }
报错:
个人记录最简单而行之有效的方法
1 public ActionResult JSon(){ 2 NorthwindEntities db = new NorthwindEntities(); 3 db.Configuration.ProxyCreationEnabled = false; 4 Employees per = db.Employees.Where(u => u.EmployeeID == 1).FirstOrDefault(); 5 return Json(per, JsonRequestBehavior.AllowGet); 6 }
解决:
百度后发现方法挺多,个人认为这个比较好用
原文地址:https://www.cnblogs.com/AardWolf/p/10673304.html
时间: 2024-10-05 21:02:40