title: Ajax-Call to get JSON Result from Controller (returning IList) in Asp.Net MVC always errors
body: <p>I am trying to make an AJAX-Call (Javascript) in order to get a <code>IList</code> created in a Controller-method.</p>
  
  <p>index.js:</p>
  
  <pre><code>function getList() {
      $.ajax({
          url: myUrl, 
          type: "GET",
          dataType: "json",    
          success: function (response) {
              if (response) {
                  //do sth
              }
          },
          error: function (response) {   
              alert("error");  //always error
              console.log(response); //object with just default functions
          }
     });
  
  }
  </code></pre>
  
  <p>MyController.cs:</p>
  
  <pre><code> public IList&lt;SomeItem&gt; loadList()
   {
          var items = db.SomeItemSet.Include(item =&gt; item.Sth).ToList();
  
          IList&lt;SomeItem&gt; resultList = new List&lt;SomeItem&gt;();
  
          for (int i = 0; i &lt; items.Count(); i++)
          {
              //if(condition)
                 resultList.Add(items[i]);                  
          }
          return resultList;
  }
  
  public JsonResult loadListJson()
  {
      return Json(new { response = loadList() }, JsonRequestBehavior.AllowGet);
  }
  </code></pre>
  
  <p>A breakpoint in the Controllermethod shows me that it is executed. The list is not null. </p>
  
  <p>I also tried to declare the method as Action Result (return json without jsonreqbehaviour) and doing type: POST in the ajax-Call. What do you think could fail here?</p>
  
  <p>The network debugging panel shows the code </p>
  
  <blockquote>
    <p>302:found</p>
  </blockquote>
  
  <p>(but not 200:OK) when trying to loadListJson.</p>
  
  <p>Exception:</p>
  
  <blockquote>
    <p>System.InvalidOperationException: A circular reference was detected
    while serializing an object of type
    'System.Data.Entity.DynamicProxies.SomeItem_9D..'.    at
    System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object
    o, StringBuilder sb, Int32 depth, Hashtable objectsInUse,
    SerializationFormat serializationFormat, MemberInfo currentMember)<br>
    at
    ...</p>
  </blockquote>