I am making a simple MVC4 application with C# and jQuery. In this application, when the user presses a button with the id of SaveCheckboxChanges I want to send two arrays of data to the server, via ajax, using jQuery.
These arrays of data are then read by the server and processed accordingly.
The controller method:
[HttpPost]
public ActionResult UpdateCheckBoxes(string requiresSetupArray, string disabledArray){
return Json("chamara", JsonRequestBehavior.AllowGet);
}
The Javascript jQuery code:
$("#SaveCheckboxChanges").click(function (event) {
if (!$("#SaveCheckboxChanges").hasClass("disabled")) {
var requiresSetupArray = [0, 1, 2];
var disabledArray = [4, 5, 6];
$.ajax({
url: '/Material/UpdateCheckBoxes',
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({requiresSetupArray: requiresSetupArray, disabledArray: disabledArray }),
success: function (data) {
alert("Success ")
},
error: function () {
alert("error");
}
});
}
});
The problem so far is that even though the method in the controller is being called correctly, the parameters are always null! What am I missing? Why is my Ajax method not deliverying the information?
string. They should bestring[](orint[])