Wednesday, January 14, 2015

A circular reference was detected while serializing an object of type 'System.Data.Entity

How to avoid such problem....

This problem in JSON when send data to view. So solve this follow below step

Step1: Go to your controller method from where your JsonResult method sending value to view.
Step2: Add below code before return type inside method.
db.Configuration.ProxyCreationEnabled = false;

Step3: Now run and check. Hope your problem will be resloved.

Full code are given below which is residing in the controller.

[HttpGet]
        public JsonResult AddressDetails()
        {
            db.Configuration.ProxyCreationEnabled = false;
            return Json(db.Address.ToList(), JsonRequestBehavior.AllowGet);
        }