Json return in Orchard CMS

Topics: Administration
Oct 23, 2012 at 4:06 PM


I am trying to get Json from one of my Orchard Action but due to some problem I am not able to get json result.I am doing this :-

     public JsonResult GetPatientUserList()
            var UserId = _membershipService.GetUser(User.Identity.Name);
            if (UserId != null)
                var UserName = UserId.Id;
                var GetPatient = _patientService.GetPatientList(UserName);
                if (GetPatient.Count() > 0)
                    return Json(GetPatient, JsonRequestBehavior.AllowGet);
                return Json("There are some problem occurred,please try again", JsonRequestBehavior.AllowGet);
            return Json("There is some problem occured please try again",JsonRequestBehavior.AllowGet);

But it is giving me following error "

A circular reference was detected while serializing an object of type 'Orchard.ContentManagement.Records.ContentItemRecord'.



Oct 23, 2012 at 4:42 PM

You can't return content items like that, they were not designed for this. You need to create a specific class, aka Data Transfer Object. It's like a View in the MVC paradigm.