title: Using $.ajax to POST XML to MVC Controller method
body: <p>I have a simple controller function like this:</p>
  
  <pre><code>&lt;HttpPost&gt;
  Function SaveXML(payload As String) As Boolean
      If payload IsNot Nothing AndAlso payload.Length &gt; 0 Then
          Return True
      Else
          Return False
      End If
  End Function
  </code></pre>
  
  <p>Which I'm calling from JavaScript like this:</p>
  
  <pre><code>function SaveXML() {
  
      var payload = '&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;data&gt;XML_GOES_HERE&lt;/data&gt;';
  
      // Calls controller correctly but data is null
      $.ajax({
          url: "/Data/SaveXML/",
          type: "POST",
          processData: false,
          contentType: "text/xml",
          data: payload
      })
      .done(function () { alert('Application saved.'); })
      .fail(function () { alert('Application failed to save.'); });
  
  }
  </code></pre>
  
  <p>I'm using the example on the <a href="https://api.jquery.com/jQuery.ajax/" rel="nofollow noreferrer">JQuery documentation</a> as a base with some advice from <a href="https://stackoverflow.com/questions/3099369/jquery-ajax-post-to-web-service">here</a>, <a href="https://stackoverflow.com/questions/7345107/jquery-ajax-post-xml-structure-filter-chain">here</a>, and <a href="https://stackoverflow.com/questions/3099369/jquery-ajax-post-to-web-service">here</a>. I've tried it with and without <code>processData: false</code> and it makes no difference.</p>
  
  <p>When the call comes in to the Controller method the payload is <code>null</code>. <a href="https://stackoverflow.com/questions/26976402/using-ajax-or-post-to-call-mvc-5-controller-method">If I post a simple string using some very similar code everything works fine</a>. What precisely needs to be done in order to post XML to a Controller via <code>$.ajax</code>? Is it at the JavaScript or Controller end that the problem lies?</p>