Jquery .ajax not posting data correctly in asp.net mvc site -- formcollection empty
<p>I'm using jquery to submit my form (with id "#myForm" here) as follows:</p>

<pre><code>$(document).ready(function() {  
        $("#my_form").submit(function(event) {  
            $.ajax(  
          {  
              type: "POST",  
              url: $("#my_form").attr("action"),  
              contentType: "application/json; charset=utf-8",  
              data: ("#my_form").serialize(),  
              success: function(result) {  
                  alert('hi');  
              },  
              error: function(req, status, error) {  
                  alert("Sorry! We could not process the form at this time.");  
              }  
          }  
         );  
         event.preventDefault();  
        });//end submit for my_form  
    });//end document ready
</code></pre>

<p>If I view the data being posted, I see the following </p>

<p>POST /PageContents/Edit HTTP/1.1<br />
x-requested-with: XMLHttpRequest<br />
Accept-Language: en-us<br />
Referer: [EDITED OUT BY ME]<br />
Accept: <em>/</em><br />
Content-Type: application/json; charset=utf-8<br />
Accept-Encoding: gzip, deflate<br />
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR   2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR   3.5.30729)<br />
Host: www.somesite.com:3852<br />
Content-Length: 142<br />
Connection: Keep-Alive<br />
Pragma: no-cache  </p>

<p>id=1&amp;small_title=Welcome+to!!!&amp;big_title=Chicago!!!&amp;body=here+is+some+stuff+for+the+body.!!!&amp;subheading=The+place+for+pizza!!</p>

<p>But this does not get mapped to the correct action because the Request.Forms collection is empty.</p>

<p>If I submit this form without javascript and just use normal HTML, the data posted looks like this:  </p>

<p>POST /PageContents/Edit HTTP/1.1<br />
Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, <em>/</em><br />
Referer: [EDITED OUT BY ME]<br />
Accept-Language: en-us<br />
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)<br />
Content-Type: application/x-www-form-urlencoded<br />
Accept-Encoding: gzip, deflate<br />
Host: www.somesite.com:3852<br />
Content-Length: 164<br />
Connection: Keep-Alive<br />
Pragma: no-cache  </p>

<p>small_title=Welcome+to%21%21%21&amp;big_title=Chicago%21%21%21&amp;subheading=The+place+for+pizza%21%21&amp;body=here+is+some+stuff+for+the+body.%21%21%21&amp;id=1  </p>

<p>You can see, the data being posted properly, so my routing all works and the correct action is called.  </p>

<p>All of the fields in my form do indeed have a name attribute.</p>

<p>Thanks, and apologies for the lengthy post.</p>
