I have tried many stackoverflow posts, but I have always the same result. The passed int array always null.
Pass array to mvc Action via AJAX
Here the asp.net mvc action which accept the int array of ids.
[HttpPost]
public ActionResult Downloads(int[] ids){
return RedirectToAction("Exports", ids);
}
This is the ajax call, which is send the values.
var url = '@Url.Action("Downloads")';
var values = [1,2,3];
$.ajax({
url: url,
type: 'POST',
dataType: "json",
contentType: 'application/json; charset=utf-8',
traditional: true,
data: JSON.stringify({ids: values })
});
I have no idea what I make wrong.
I have passed the ajax's date like a simple array: data: values
or without stringify, but the asp.net mvc never accept the int array. It seems the traditional
parameter of ajax
object does not do anything.