How can I send int array from ajax to c# mvc?

Anton Lyhin picture Anton Lyhin · Feb 2, 2012 · Viewed 42.3k times · Source

How can I send int array from $.ajax to c# mvc?

Answer

Daniel picture Daniel · Feb 2, 2012
$.ajax({
          url: <Url of the action>,
          type: "POST",
          data: JSON.stringify([1,2,3]),
          dataType: "json",
          contentType: 'application/json; charset=utf-8'
});

and in the action.

public ActionResult ReceiveIntArray(int[] ints)
{
   ...
}

mvc should parse the json automatically.

check out this question.