title: Sending Multiple Items to MVC Controller via jQuery.Ajax
body: <p>If youa are serializing a form using something like jQuery, it will often map the JSON keys and values to the properties of a object on the Controller Action you are posting to. So:</p>
  
  <p>jQuery:</p>
  
  <pre><code>function PostForm() {
      $.ajax({
          url: "/Home/TestMVC",
          type: "POST",
          dataType: "application/JSON",
          data:  $('#form').serialize(),
          complete: callFunction
          }
      });
  </code></pre>
  
  <p>Presuming main details contains elements which will have the name of the parameter as a key they should map to the object directly:</p>
  
  <p>Action:</p>
  
  <pre><code>public void TestMVC(MyObject obj)
  {
  //Obj should now contain the data from the serialised form
  }
  </code></pre>
  
  <p>POST:</p>
  
  <pre><code>Name: "Bob"
  Age: "999"
  Sex: "Unknown"
  </code></pre>
  
  <p>Does anyone know how this works?  It's breaking every time I pass the form <strong><em>and any additional data</em></strong> to the controller. </p>
  
  <p>I would like to send the contents of the data as well as a QueryString which could contain any number and types of key/value pairs to the controller. I can extract these key/value pairs on the server since I cannot create an object for them on the method signature. However, this fails to work as intended. </p>
  
  <p>jQuery:</p>
  
  <pre><code>function PostForm() {
  
      $.ajax({
          url: "/Home/TestMVC",
          type: "POST",
          dataType: "application/JSON",
          data: 
          { 
             Obj: $('#form').serialize(),
             TheWeirdQueryString: $('.additionalParams').serialize(),
          }
      });
  };
  </code></pre>
  
  <p>Action:</p>
  
  <pre><code>public void TestMVC(MyObject obj, String TheWeirdQueryString)
  {
  //Obj now does NOT contain the element, it is NULL. Whereas TheWeirdQueryString works fine. 
  }
  </code></pre>
  
  <p>Post:</p>
  
  <pre><code>Obj: name=bob&amp;age=999&amp;sex="unknown"
  TheWeirdQueryString: param1=1&amp;param2=2
  </code></pre>
  
  <p>I think this is because I have actually created a JSON object as the Data and set the properties to the name of the object. </p>
  
  <p>There is a difference in the POST values which appear in Firebug. When I post the object alone, the POST values are all the keys of the object/form with their corresponding values. In the second example there are two simple properties, The name I gave them, each containing a QueryString (<code>Foo=1&amp;Bar=2</code>) and MVC cannot map a QueryString to the members of an object (or so it would appear).</p>
  
  <p>Is there anyway at all to get to work like it does in the first instance, but also to send extra data to a 2nd argument on the Action? I am guessing it's to add an extra property to all the existing ones created when jquery does the serialisation of the form. </p>
  
  <p>The POST I actually want is:</p>
  
  <pre><code>Name: "Bob"
  Age: "999"
  Sex: "Unknown"
  TheWeirdQueryString: param1=1&amp;param2=2
  </code></pre>