title: ASP.NET MVC Ajax: Passing an IList from the View to the Controller
body: <p>I need to pass the grid rows from the view to the controller using POST. The idea is to pass an IList of objects (people) that have the following structure:</p>
  
  <ul>
  <li>String Name</li>
  <li>String Address</li>
  <li>String ID</li>
  </ul>
  
  <p>I want to read the data from the JQGrid and pass it to the controller to fill the IList.</p>
  
  <p>I'm trying to build the data object to pass through the Ajax data parameter.</p>
  
  <p>Here is the Javascript code:</p>
  
  <pre><code>$("#saveButton").click(
   function()
   {
     var returnData = '{';
     var existingIDs = $('#listPeople').getDataIDs();
  
     if (idsPeople.length &gt; 0)
     {
       for (i=0;i&lt;idsPeople.length;i++) 
       {
  
  //Trying to build the obejct data
  
  ret = ret + '"people['+ i +'].Name":' $('#listPeople').getRowData(idsPeople[i]).Name + ',';
  
  ret = ret + '"people['+ i +'].Address":' $('#listPeople').getRowData(idsPeople[i]).Address+ ',';
  
  ret = ret + '"people['+ i +'].Id":' $('#listPeople').getRowData(idsPeople[i]).Id+ ',';
  
  //If it has more than one element
        if (idsPeople.length&gt;1 &amp;&amp; (i+1)&lt;idsPeople.length)
        {
          ret = ret + ',';
        }
      }
    }
  
  ret = ret + '}';
  </code></pre>
  
  <p>My Ajax function for sending:</p>
  
  <pre><code>var url_all = '&lt;%=Url.Action("SaveData") %&gt;;
  
  $.ajax({
  type: "POST",
  url: url_all,
  data: ret,
  dataType: "json",
  success: function(){
     alert("OK");
   },
  error: function(){
     alert("Error: check SaveData");
   } 
  });
  </code></pre>
  
  <p>My controller:</p>
  
  <pre><code>public ActionResult SaveData(IList&lt;PeopleHeader&gt; people){
  
     // using debug to know if "people" variable has any values
  
     return Json(true);
  }
  </code></pre>
  
  <p>The problem I'm getting is an error: "System.NotSupportedException: Fixed size collection", and no data is being delivered.</p>
  
  <p>I think my problem relies on creating the object... is there any simpler way of doing this procedure?</p>
  
  <p>Thanks in advance,</p>