I have 3 tables in hierarchical structure namely album, artist and genre.
album table derived from genre and artist.
artist properties
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ArtistId { get; set; }
public string Name { get; set; }
public List<Album> Albums { get; set; }
genre properties:
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int GenreId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public List<Album> Albums { get; set; }
album properties:
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int AlbumId { get; set; }
[Required(ErrorMessage = "pls select Genre")]
[ForeignKey("Genre")]
public int GenreId { get; set; }
[ForeignKey("Artist")]
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();
return Json(gridDataResult, JsonRequestBehavior.AllowGet);
}
till here data is coming but in view page i used following code:
function loadAlbums(self)
{
$.ajax({
url: "/MuzzicStore/GetAlbums?rowsPerPage=" + self.rowsPerPage() + "&pageNo=" + self.page(),
type: "get",
success: function (data) {
alert('success');
},
error: function () {
alert("Error");
}
});
}
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.