Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Ajax Sending Null Parameters to Controller

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading