Passing multiple ajax parameters to mvc controller

60 views Asked by At

I can pass a serialized form to a mvc controller no problems with code below and all is populated

$("#btnExecuteJob").on("click", function (e) {

    var frmForm1 = $("#form1").serialize();
    
    $.ajax({
        cache: false,
        url: "/mvcController/executeJob",
        dataType: 'json',
        type: 'POST',
        data: frmForm1,
        success: function (resp) {},
        error: function (resp) {}
    });
});

Controller

  [HttpPost]   
   public ActionResult executeJob(runDetails jobDetails)
   { 
      //
      // Process  
      //


        return View();
     }

I have added a second form to my view and now want to pass both to the controller so I tried

$("#btnExecuteJob").on("click", function (e) {

    var frmForm1 = $("#form1").serialize();
    var frmForm2 = $("#form2").serialize();
    
    $.ajax({
        cache: false,
        url: "/jobScheduler/executeJob",
        dataType: 'json',
        type: 'POST',
        data: {
                jobDetails: frmForm1,
                jobParameters: frmForm2
        },
        success: function (resp) {},
        error: function (resp) {}
    });
});

Controller

   public ActionResult executeJob(runDetails jobDetails, runParams jobParameters)
   { 
      //
      // Process  
      //


        return View();
     }

and neither jobDetails or jobParams is populated, both work individually as first example and all details are populated, any help much appreciated,
both forms really need to be separate in the controller

0

There are 0 answers