title: POST JSON array data with parameters in Web API
body: <p><strong>UPDATED:</strong></p>
  
  <p>I am creating a simple app using MVC and Web API as an exercise which is new to me. It lets user paste a JSON data array into a textarea and pass it on to a Web API controller via AJAX with a sort parameter where value is based on the chosen option in the dropdown. The API controller will perform the sorting. Once sorted, it will return the URL containing the parameter value similar to one's below:</p>
  
  <p>Home/Index/?sort=age <br>
  Home/Index/?sort=lastName<br>
  Home/Index/?sort=registered</p>
  
  <p>I am not certain where to put the query string parameter.</p>
  
  <p><a href="https://i.stack.imgur.com/phhgw.png" rel="nofollow"><img src="https://i.stack.imgur.com/phhgw.png" alt="enter image description here"></a></p>
  
  <p><strong>UPDATED:</strong></p>
  
  <p>Here's my AJAX call so far..</p>
  
  <pre><code>$(document).ready(function () {
      var profiles = $('#txtJSONData').val().replace(/(\r\n|\n|\r)/g,"");
      $('#btnSubmit').click(function () {
          $.ajax({
              url: '/api/default',
              data: JSON.stringify(JSON.parse(profiles)),
              type: 'POST',
              dataType: 'application/json',
              success: function(data) {
                  alert("success");
              },
              error: function() {
                  alert("error");
              }
          });
      });
  });
  </code></pre>
  
  <p><strong>UPDATED:</strong></p>
  
  <p>I am already getting the values of the JSON array being posted. However, I also need to pass in the sort query string parameter and its value to perform the sorting. I am not sure where to put it. Do I need to append it on the API route? Or let MVC controller handle it?</p>
  
  <pre><code>public class DefaultController : ApiController
  {
      [Route("api/default")]
      [HttpPost]
      public HttpResponseMessage Post([FromBody] JToken jsonBody)
      {
  
      }
   }
  </code></pre>
  
  <p>Been trying to search for a solution both here and over the web but couldn't find a similar scenario with mine. Any help and/or suggestions will be highly appreciated. Thanks in advance!</p>