title: Json Serialization Exception
body: <p>The relationship between models are: X has many Y; Y has many Z:   </p>
  
  <pre><code>class X 
  {
      int Id { get; set; }
      [JsonIgnore]
      IList&lt;Y&gt; Y { get; set; }
  }
  
  class Y
  {
      int Id { get; set; }
      X x { get; set; }
      [JsonIgnore]
      IList&lt;Z&gt; Z { get; set; }
  }
  
  class Z
  {
      int Id { get; set; }
      Y y { get; set; }
  }
  
  public class YBinder : DefaultModelBinder
  {
      readonly IQuizRepository _quizRepository = DependencyResolver.Current.GetService&lt;IQuizRepository&gt;();
  
      public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
      {
          var y = (Y)base.BindModel(controllerContext, bindingContext);
          if (problem.Chapter != null)
          {
              y.X = _quizRepository.getX(y.X.Id);
          }
          return y;
      }
  }
  
  public class ZBinder : DefaultModelBinder
  { 
      readonly IQuizRepository _quizRepository = DependencyResolver.Current.GetService&lt;IQuizRepository&gt;();
  
      public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
      {
          var z = (Z)base.BindModel(controllerContext, bindingContext);
          if (z.Y != null)
          {
              z.Y = _quizRepository.getY(z.Y.Id);
          }
          return z;
      }
  }
  </code></pre>
  
  <p>My problem is that grid X and Y are populated but gird Z throws a <code>JsonSerializationException</code>.  Here is the action which populates grid Z and throws an exception:</p>
  
  <pre><code>public ContentResult Problems(JqInViewModel jqParams)
  {
      var problems = _quizRepository.Problems(jqParams.page - 1, jqParams.rows, jqParams.sidx, jqParams.sord == "asc");
  
      var totalProblems = _quizRepository.TotalProblems(false);
  
      return Content(JsonConvert.SerializeObject(new
      {
          page = jqParams.page,
          records = totalProblems,
          rows = problems,
          total = Math.Ceiling(Convert.ToDouble(totalProblems) / jqParams.rows)
      }, new CustomDateTimeConverter()), "application/json");
  }
  </code></pre>
  
  <p>The problem is somwewhere with JSON; when I put <code>[JsonIgnore]</code> in class Z for debugging 
  then the grid loads without an exception, otherwise it gives <code>Newtonsoft.Json.JsonSerializationException</code>.</p>
  
  <pre><code>class Z
  {
      int Id { get; set; }
      [JsonIgnore]          // this removes exception but then I cant bind y in grid
      Y y { get; set; }
  }
  </code></pre>
  
  <p>Can someone help me figure out what is wrong?</p>