title: Posting JSON data via jQuery to ASP .NET MVC 4 controller action
body: <p>I'm having trouble trying to pass a complex JSON object to an MVC 4 controller action.  As the JSON content is variable, I don't want MVC to map individual properties/elements of the JSON to parameters in the action method's parameter list.  I just want to get the data as a single JSON string parameter in the controller action.</p>
  
  <p>Here's the signature of my action method:</p>
  
  <pre><code>    [HttpPost]
      [ValidateInput(false)]
      public string ConvertLogInfoToXml(string jsonOfLog)
  </code></pre>
  
  <p>And here's my attempt to post some JSON data, from my browser:</p>
  
  <pre><code>    data = {prop: 1, myArray: [1, "two", 3]}; 
      //'data' is much more complicated in my real application
      json = {jsonOfLog: data};
  
      $.ajax({
          type: 'POST',
          url: "Home/ConvertLogInfoToXml",
          data: JSON.stringify(json),
          success: function (returnPayload) {
              console &amp;&amp; console.log ("request succeeded");
          },
          error: function (xhr, ajaxOptions, thrownError) {
              console &amp;&amp; console.log ("request failed");
          },
          dataType: "xml",
          contentType: "application/json",            
          processData: false,
          async: false
      });
  </code></pre>
  
  <p>When I hit my breakpoint at the beginning of the ConvertLogInfoToXML method, jsonOfLog is null.</p>
  
  <p>If I change what 'json' variable is set to in the JavaScript to have the jsonOfLog property be a simple string, e.g. :</p>
  
  <pre><code>json = { jsonOfLog: "simple string" };
  </code></pre>
  
  <p>then when my breakpoint at the beginning of the ConvertLogInfoToXML method is hit, jsonOfLog is the value of the string (e.g. "simple string").</p>
  
  <p>I tried changing the type of the jsonOfLog parameter in the action method to be of type object:</p>
  
  <pre><code>    [HttpPost]
      [ValidateInput(false)]
      public string ConvertLogInfoToXml(object jsonOfLog)
  </code></pre>
  
  <p>Now, with the original JavaScript code (where I'm passing a more complex 'data' object), jsonOfLog gets the value of {object}.  But the debugger doesn't show any more details in a watch window, and I don't know what methods I can use to operate on this variable.</p>
  
  <p>How do I pass JSON data to a MVC controller, where the data passed is a stringified complex object?</p>
  
  <p>Thanks,
  Notre</p>