title: Posting JSON data to MVC controller using Ajax
body: <p>I've been trying to pass JSON data into MVC4 controller, which hasn't worked so far.</p>
  
  <p>Also, I've googled on this a thousand of times.</p>
  
  <p>The key point to solve this issue out there was to stringify the JSON object, define a model and get the parameter as the defined model, or define contentType.</p>
  
  <p>I did those but defining a model for passing JSON into controller.</p>
  
  <p>If I have to define the model every time I try to pass JSON parameter to server, I'm not going to build my app on MVC4, I will give up!</p>
  
  <p>Is there another way to get JSON data from Ajax call in a controller without creating a model for the JSON data?</p>
  
  <p>Here's my example code.</p>
  
  <pre><code>[HttpPost]
  public ActionResult DATACRUD(string XmlParms)
  {
      return Json(new{ data = XmlParms });
  }
  // Just example.
  </code></pre>
  
  <p>And Ajax call is.</p>
  
  <pre><code>$.ajax({
          type: "POST",
          url: "DATACRUD.json",
          data: JSON.stringify({data:"test"}),
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          async: false, //_async,
          success: function (result) {
          }
  });
  </code></pre>
  
  <p><strong>Ajax successfully invokes the action in a controller, but the parameter is null.</strong></p>
  
  <p>Please don't tell me defining model for the JSON parameter is the only one way to solve this issue.</p>
  
  <p>It would be very frustrating if I have to do that.</p>
  
  <hr>
  
  <p>UPDATE:</p>
  
  <p>If I have to match the key name and the param name, I will give up as well.</p>
  
  <p>JSON data usually looks like this in my app.</p>
  
  <pre><code>{
      "service": "COMMON",
      "method": "MENU_SUBLIST",
      "UID": "1000007",
      "ULID": "stackoverflow",
      "UNM": "queston", 
      "SITE": "1",
      "DEPT": "2",
      "LANG": "ko", 
      "MENUID": "0000",
      "STEPMENU": "",
      "ACTIONNAME": "" 
  }
  </code></pre>
  
  <p>But the thing is that there're many kinds of JSON data including a variety of key names.</p>
  
  <p>I cannot match the names all one by one. In this case, what should I do?</p>
  
  <p>( <strong>And just make sure</strong>, wrapping the data like this below isn't a solution for me, <strong>there's a compatibility issue.</strong> )</p>
  
  <pre><code>{ XmlParms : {         
      "service":"COMMON",
      "method":"MENU_SUBLIST",
      "UID":"1000007",
      "ULID":"stackoverflow",
      "UNM":"queston",
      "SITE":"1",
      "DEPT":"2",
      "LANG":"ko",
      "MENUID":"0000",
      "STEPMENU":"",
      "ACTIONNAME":""
      }
  }
  </code></pre>