Click here to Skip to main content
15,878,231 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 3 tables in hierarchical structure namely album, artist and genre.
album table derived from genre and artist.

artist properties

      public int ArtistId { get; set; }
      public string Name { get; set; }
      public List<Album> Albums { get; set; }

genre properties:
       public int GenreId { get; set; }
       public string Name { get; set; }
       public string Description { get; set; }
      public List<Album> Albums { get; set; }

album properties:

       public int AlbumId { get; set; }
          [Required(ErrorMessage = "pls select Genre")]

       public int GenreId { get; set; }

       public int ArtistId { get; set; }

       [Required(ErrorMessage = "Title is required")]
       public string Title { get; set; }
       [Required(ErrorMessage = "Price is required")]
       [Range(0.01, 100.00,ErrorMessage = "Price must be between 0.01 and 100.00")]
       public decimal Price { get; set; }
       public string AlbumUrl { get; set; }
       public string Comments { get; set; }
       public   Genre Genre { get; set; }
       public  Artists Artist { get; set; }

need to retrieve the data from album with respective Genre name corresponding to genre id and artist name corresponding to artist name.

in controller
public ActionResult GetAlbums(int rowsPerPage, int pageNo)
           GridDataResult gridDataResult = new GridDataResult();
           var albums = logic.GetAlbum();
           gridDataResult.TotalRowCount = albums.Count;
           int totalPages = 1;
           if (rowsPerPage > 0)
               totalPages = gridDataResult.TotalRowCount / rowsPerPage;
               if (gridDataResult.TotalRowCount % rowsPerPage != 0)
                   totalPages += 1;
           gridDataResult.TotalPageCount = totalPages;

           gridDataResult.GridData = albums.Skip((pageNo - 1) * rowsPerPage).Take(rowsPerPage).ToList();

        // var data =JsonConvert.SerializeObject(gridDataResult, Formatting.None);

         //return Json(data, JsonRequestBehavior.AllowGet);
         return Json(gridDataResult, JsonRequestBehavior.AllowGet);

till here data is coming but in view page i used following code:

 function loadAlbums(self)
                url: "/MuzzicStore/GetAlbums?rowsPerPage=" + self.rowsPerPage() + "&pageNo=" +,
                        type: "get",
                        success: function (data) {
                            //var serverData = ko.utils.parseJson(data);
                        error: function () {


its giving an error

A circular reference was detected while serializing an object of type 'MuzzicMantra.Data.Domain.Album'.

tried lot of thongs but couldnt resolve.

help will be appreciable.
Updated 12-Aug-21 5:25am
Mehdi Gholam 13-Oct-14 4:20am    
If you are passing it to the web browser there is very little you can do, other than avoid circular references in your data structure.

It worked for me

3 things require for resolvingcircular reference :

1. Apply [JsonIgnore] to navigational properties

2. In global.asax

GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;

3. serialize the data

string json = JsonConvert.SerializeObject(gridDataResult.GridData, Formatting.None);
return Json(json, JsonRequestBehavior.AllowGet);
Share this answer
my solution depends on using EF6 & LINQ


var x =>{


return json(x);
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900