title: passing complex object into mvc controller action from javascript
body: <p>I want to pass an object into my mvc controller action and return a list of values but im having some difficulties, can anyone see where Im going wrong ?</p>
  
  <p>Heres my javascript</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 model = { MainOrganisation : frmOrg.elements["Schedule_OrgId"].value,
                  ContractRefs: $.map($('#js_multiselect_to_1 option'), function (ele) { return ele.value; })
              };
  
              $.ajax({
                  type: 'GET',
                  dataType: 'json',
                  cache: false,
                  url: '/ReportScheduler/GetReportUsers',
                  data: model,
                  contentType: "application/json; charset=utf-8",
                  success: function (data, textStatus, jqXHR) {
                      //Do Stuff
                      $("#DailyInvoiceItems").html(data.Id);
                  },
                  error: function (jqXHR, textStatus, errorThrown) {
                      //Do Stuff or Nothing
                  }
              });</code></pre>
  </div>
  </div>
  </p>
  
  <p>and this is the action method on my controller</p>
  
  <pre><code>[HttpGet]
      public async Task&lt;JsonResult&gt; GetReportUsers(ReportUserRequest request)
      {
          GetUserRequest userRequest = new GetUserRequest(request.MainOrganisation);
          var userResponse = await this._userService.GetAllUsersForOrgAsync(userRequest);
  
          return Json(userResponse.users, JsonRequestBehavior.AllowGet);
      }
  </code></pre>
  
  <p>the model im passing in is structured  like this</p>
  
  <pre><code>public class ReportUserRequest
  {
      public int MainOrganisation { get; set; }
      public List&lt;string&gt; ContractRefs { get; set; }
      public ReportUserRequest()
      {
          this.ContractRefs = new List&lt;string&gt;();
          this.MainOrganisation = 0;
      }
  }
  </code></pre>
  
  <p>The ajax call jumps into the controller action but when I inspect the object, only the MainOrganisation has a value, the list is null, but I have checked on the clientside and it is populated with values so theyre being 'lost' somewhere</p>