I want to pass array value from view to the controller action using ajax. I have created jquery and controller method as bellow, but its not working.
in my javascript file,
$("#btnSave").click(function () {
var data = [];
$("#utiltyTable tr.maintr").each(function () {
var selectedMail = [];
var selectedMobile = [];
var categoryId = $(this).find("td.uCategory").find("input[type='hidden']").val();
$(this).find("td.uEmail").find("select :selected").map(function (i, el) {
selectedMail.push({ "value": $(el).val(), "item": $(el).text() });
});
$(this).find("td.uSMS").find("select :selected").map(function (i, el) {
selectedMobile.push({ "value": $(el).val(), "item": $(el).text() });
});
data.push({ categoryId: categoryId, selectedMail: JSON.stringify(selectedMail), selectedMobile: JSON.stringify(selectedMobile) })
});
console.log(data);
$.ajax({
url: '@Url.Action("UtilityEmailSMS", "Account")',
type: 'POST',
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(data),
success: function (data) {
}
});
});
Controller action method as bellow,
[HttpPost]
public ActionResult UtilityEmailSMS(string[] data)
{
return View();
}

public ActionResult UtilityEmailSMS(object[] data)i am also getting null indataselectedMail: selectedMail(notJSON.stringify(selectedMail)) and ditto forselectedMobile: selectedMobile. You need a model to bind to that matches the data you sending