Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 977
Anton Lyhin Avatar asked Feb 02 '12 09:02

Anton Lyhin


People also ask

Can we send array through Ajax?

You can simply pass a JavaScript Array variable in the $. ajax as any other variable. On PHP script you can directly use it as a normal PHP Array.

Can Ajax send data?

ajax() method allows you to send asynchronous http requests to submit or retrieve data from the server without reloading the whole page.

What is array in Ajax?

DataTables has the ability to read data from virtually any JSON data source that can be obtained by Ajax. This can be done, in its most simple form, by setting the ajax option to the address of the JSON data source.


1 Answers

$.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.

like image 102
Daniel Avatar answered Sep 22 '22 13:09

Daniel