title: MVC3 Pass back List of Objects with Lists
body: <p>I need to pass an array of objects, which contain arrays, from javascript to a MVC actionresult method.  Basically I have a KeyValuePair whose key is an array of strings, and I need to pass back a list of these KeyValuePairs.  In the code, I have a list of keys I've changed, and a JS object that holds key->value pairs.  My javascript object that I try to pass back should be the same format as my class.  I tried JSONing it as well, but no luck.</p>
  
  <p>Thanks.</p>
  
  <pre><code>public class ChangedItem
  {
      public IEnumerable&lt;string&gt; Key { get; set; }
      public int Value { get; set; }
  
      public ChangedItem()
      {
      }
  
      public ChangedItem(IEnumerable&lt;string&gt; key, int value)
      {
          Key = key;
          Value = value;
      }
  }
  
  [HttpPost]
  public ActionResult UpdateResults(IEnumerable&lt;ChangedItem&gt; changedItems)
  {
      return RedirectToAction("Index");
  }
  
  function getChangedItems() {
      var ChangedItems = new Array();
      for (var i = 0; i &lt; _ChangedItemKeys.length; i++) {
          var ChangedItem = {};
          ChangedItem.Key = _ChangedItemKeys[i];
          ChangedItem.Value = _ChangedItems[_ChangedItemKeys[i]];
          ChangedItems[i] = ChangedItem;
      }
      return ChangedItems;
  }
  
  function submitNewVals() {
      $.ajax({
          url: '/Home/UpdateResults',
          type: 'POST',
          dataType: 'json',
          data:
          {
              changedItems: getChangedItems()
          }
      });
  }
  </code></pre>
  
  <p>My request data is detailed below, and I get 6 items in my action result, its just that inside each of those items the key is null and value is 0:</p>
  
  <pre><code>changedItems[0][Key][]:BoxeR
  changedItems[0][Key][]:Proleague
  changedItems[0][Key][]:Total
  changedItems[0][Key][]:2005
  changedItems[0][Key][]:Quarter 2
  changedItems[0][Key][]:Actual
  changedItems[0][Value]:123
  changedItems[1][Key][]:BoxeR
  changedItems[1][Key][]:Proleague
  changedItems[1][Key][]:Team
  changedItems[1][Key][]:2005
  changedItems[1][Key][]:Quarter 1
  changedItems[1][Key][]:Actual
  changedItems[1][Value]:123
  changedItems[2][Key][]:BoxeR
  changedItems[2][Key][]:Proleague
  changedItems[2][Key][]:Team
  changedItems[2][Key][]:2005
  changedItems[2][Key][]:Quarter 1
  changedItems[2][Key][]:Estimate
  changedItems[2][Value]:123
  changedItems[3][Key][]:BoxeR
  changedItems[3][Key][]:Proleague
  changedItems[3][Key][]:Team
  changedItems[3][Key][]:2005
  changedItems[3][Key][]:Quarter 2
  changedItems[3][Key][]:Actual
  changedItems[3][Value]:123
  changedItems[4][Key][]:BoxeR
  changedItems[4][Key][]:Proleague
  changedItems[4][Key][]:Team
  changedItems[4][Key][]:2005
  changedItems[4][Key][]:Quarter 2
  changedItems[4][Key][]:Estimate
  changedItems[4][Value]:123
  </code></pre>
  
  <p>I tried playing around in fiddler and changing the request data format (using .Key[x], .Value), but nothing worked.</p>
  
  <p>Thanks!</p>