title: Passing JSON object and Javascript Variable through AJAX
body: <p>Im trying to pass a JSON object, and 2 javascript arrays in the same AJAX call.</p>
  
  <p>I keep recieving this error</p>
  
  <pre><code>    System.ArgumentException: Invalid JSON primitive: object
  </code></pre>
  
  <p>I believe this may be to do with the different types of variables being passed.</p>
  
  <p>Any obvious errors you can spot?</p>
  
  <p>Thanks</p>
  
  <pre><code>    var requestData = {
      "deptCode": userVar,
      "roundID": parseInt(roundIDVar),
      "moduleCode": moduleCodeVar,
      "priority": parseInt(priorityVar),
      "day": parseInt(dayVar),
      "start": parseInt(timeVar)-8,
      "length": parseInt(lengthVar),
      "weeks": weeksNum,
      "capacity": parseInt(studentsVar),
      "type": roomTypeVar,
      "otherReqs": otherReqs
  };
  var obj = JSON.stringify(requestData);
  
  $.ajax({
      type: 'POST',
      url: '/create/Submit',
      error: function (xhr, ajaxOptions, thrownError) {
          alert("Submitting Failed. Please Reload and Try Again.");
      },
      data: {JSONdata:obj,weeks:weeksVar,facilities:facilitiesValue },
      datatype: 'html',
      contentType: 'application/json',
      processData: false,
      async:false,
      success: function (data) {
          alert(data);
      }
  });
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>     public ActionResult Submit(request JSONdata, String[] Weeks, String[] facilities) {
          ViewBag.module = JSONdata.weeks;
          if(JSONdata.otherReqs==null){
              JSONdata.otherReqs = "None";
          }
          JSONdata.sent = 1;
          JSONdata.status = 0;
          JSONdata.viewed = 0;
          JSONdata.booked = 0;
          db.requests.Add(JSONdata);
  
          try
          {
              // Your code...
              // Could also be before try if you know the exception occurs in SaveChanges
  
              db.SaveChanges();
          }
          catch (DbEntityValidationException e)
          {
              foreach (var eve in e.EntityValidationErrors)
              {
                  Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                  foreach (var ve in eve.ValidationErrors)
                  {
                      Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                          ve.PropertyName, ve.ErrorMessage);
                  }
              }
              throw;
          }
          if(Convert.ToInt16(JSONdata.weeks)==1){
              for (var i = 0; i &lt; Weeks.Length; i++) {
                  weeks_request newWeek = new weeks_request();
                  newWeek.week = Convert.ToInt16(Weeks[i]);
                  newWeek.requestID = JSONdata.requestID;
                  db.weeks_request.Add(newWeek);
                  db.SaveChanges();
              }
          }
          return View();
      }
  </code></pre>