Home > Blockchain >  Ajax Sending Null Parameters to Controller
Ajax Sending Null Parameters to Controller

Time:02-18

I am trying to send 3 parameters using ajax to a Controller function. My ajax looks like

$.ajax({
    url: '../saveFields',
    data: {
           fields : fieldIDs,
           values : vals,
           ID : <%= this.Model.DatabaseID %>,
    },
    success: function (data) {
           alert("Success");
    },
    error: function (data) {
           alert("Failed");
    }
});

where fieldIDs and vals are arrays populated with integers. And the Controller call is

public ActionResult saveFields(int ID, int[] fields, int[] values)

I have a breakpoint set up right before the ajax call and the first line in the Controller function. Right before the ajax call, fieldIDs and vals are correctly populated, but then the first line of the Controller function the fields and values parameters are null. ID works fine. Any assistance as to what I am doing wrong would be greatly appreciated.

CodePudding user response:

Well, Jquery has different types of param serialization. Jquery Params

It turns out to fix that and pass an array correctly, you need to set the following property for the AJAX:

traditional: true
  • Related