title: Passing an object and primitives to a Controller via JQuery
body: <p>Started by looking at a similar thread, but the Solution there didn't work for me.</p>
  
  <p><a href="https://stackoverflow.com/questions/31148599/passing-multiple-objects-to-my-controller">Passing multiple objects to my controller</a></p>
  
  <p>Here is my javascript onclick event:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var test = function () {
          var vm = {
              "IsNew": true,
              "SelectedId": 1,
              "SelectedCode": null
          };
          var idk= JSON.stringify(vm);
          $.ajax({
              url: $("base").attr("href") + "Controller/ComplexityTest",
              method: "POST",
              contentType: 'application/json',
              data: idk,
              success: function (msg) {
                  alert('success')
              },
              error: function (jqXHR, textStatus, errorThrown) {
                  alert("Error: " + textStatus + ", " + errorThrown);
              }
          });
      };</code></pre>
  </div>
  </div>
  </p>
  
  <p>On my Controller, I have this endpoint:</p>
  
  <pre><code>    [HttpPost]
      public async Task&lt;IActionResult&gt; ComplexityTest([FromBody] MyViewModel vm, long categoryId, long personId, DateTime startDate)
      {
          //...do work
      }
  </code></pre>
  
  <p>For simplicity, let's say this is my Model:</p>
  
  <pre><code>public class MyViewModel
  {
      public bool IsNew {get; set;}
      public int SelectedId {get; set;}
      public string SelectedCode {get; set;}
  }
  </code></pre>
  
  <p>On running this, I'm able to see that vm is populated correctly. The issue is that I'm also trying to populate some additional primitives to be sent along with MyViewModel.</p>
  
  <p>I've tried adding the additional fields inside my vm initializer, and stringifying the whole thing.</p>
  
  <p>I've tried setting data to { "vm": idk, "categoryId": 1, etc... }.</p>
  
  <p>Everything I've tried so far has caused me to not only get the new parameters, but to lose my original vm object as well.</p>
  
  <p>How do I go about passing an object (class) and multiple primitives to a POST method? Do I just need to create a new DTO object containing the additional parameters, and send that instead?</p>