title: Asp.Net core MVC Javascript Ajax parameters null HttpPost
body: <p>I am writing a javascript function for a button </p>
  
  <pre><code>&lt;button type="button" class="btn btn-sm btn-outline-secondary" id="stopProcess"  onclick="stopProcess(event, @queue.AgentQueueId, @queue.AgentId)" data-toggle="tooltip"&gt;Stop&lt;/button&gt;
  </code></pre>
  
  <p>This is what my javascript function looks like </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(document).ready(function () {
          setInterval(function () {
              reloadPage()
          }, 50000);
      });
      function reloadPage() {
          window.location.reload(true);
      }
      function stopProcess(e, agentQueueId, agentId) {
          e.stopPropagation();
  
          var data = JSON.stringify({ 'agentQueueId': agentQueueId, 'agentId': agentId });
  
          $.ajax({
              type: "POST",
              url: "@Url.Action("StopTest", "Agents")",
              data: data,
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              success: function (data) {
                  reloadPage();
              },
              error: function (data) {
                  $(".alert").text("Error completing the request.");
                  $(".alert").prop("hidden", false);
              }
          });
      };
  &lt;/script&gt;
  </code></pre>
  
  <p>It correctly navigates to the function StopTest in my Agents controller but the parameters passed to it are null. </p>
  
  <p>My controller code is</p>
  
  <pre><code>[HttpPost]
          public bool StopTest(long agentQueueId, long agentId)
          {
              StopTestsResponse response = new StopTestsResponse();
              try
              {
                  response = _testAgentRepository.StopTest(new StopTestsRequest()
                  {
                      AgentId = agentId,
                      AgentQueueId = agentQueueId
                  });
              }
              catch (Exception ex)
              {
                  throw ex;
              }
              return response.Success;
          }
  </code></pre>
  
  <p>It would be of great help if anyone could point out where I am going wrong. </p>