title: Post array to ASP.NET MVC 2 Controller using AJAX
body: <p>There is <a href="https://stackoverflow.com/questions/309115/how-can-i-post-an-array-of-string-to-asp-net-mvc-controller-without-a-form">known trouble</a> with sending array to ASP.NET MVC controller. I've found a lot of solutions like <a href="https://stackoverflow.com/questions/320291/how-to-post-an-array-of-complex-objects-with-json-jquery-to-asp-net-mvc-controll">that</a>. Why don't use usual object instead array? It works good.
  Example of code:</p>
  
  <pre><code>    &lt;script&gt;
      $(function(){
          $('.asArray').click(function(){
              var array = Array();
              array[0] = 'Dima';
              array[1] = 'Ann';
              array[2] = 'John';
              $.post('/Home/Get', {data: array}, function(data){alert(data);});
          });
          $('.asObject').click(function(){ // works good
              var array = Object();
              array[0] = 'Dima';
              array[1] = 'Ann';
              array[2] = 'John';
              $.post('/Home/Get', {data: array}, function(data){alert(data);});
          });
      });
  &lt;/script&gt;
  &lt;div&gt;
      &lt;input type="button" class="asArray" value="asArray"/&gt;
      &lt;input type="button" class="asObject" value="asObject"/&gt;
  </code></pre>
  
  <h2>    </h2>
  
  <p>controller action:</p>
  
  <pre><code>public ActionResult Get(IEnumerable&lt;string&gt; data)
      {
          if (data == null)
              return Content("data == null");
          return Content("data = [" + data.Aggregate((agr, curr) =&gt; agr + ", " + curr) + "]");
      }
  </code></pre>