Floki
Floki

Reputation: 261

How to send server side jquery datatable data to the server using post request

I am using server side jquery datatable and i used the simple ajax get request and accessed jquery datatable data(like:start,draw,order,search) in my c# program.But now i have many columns so its not returing data of all datatable columns using get request so i want to use the ajax post request but i don't know how to access these datatable parameters(start,draw,order,search) and pass these in ajax post request.

GET Request: Client Side

 "ajax": "/Admin/InterestsJson"

Server Side: C#

NameValueCollection nvc = HttpUtility.ParseQueryString(Request.Url.Query);
string sEcho = nvc["draw"];
int iDisplayStart = Convert.ToInt32(nvc["start"]);
string searchValue = nvc["search[value]"];
int orderColumn = Convert.ToInt32(nvc["order[0][column]"]);
string orderDir = nvc["order[0][dir]"];

Post Request:Client side

"ajax": {
"url": "/Admin/SubInterestsJson",
"type": "POST"
}

Please tell me how to access these jquet datatable parameters and pass in post request?

Upvotes: 3

Views: 2372

Answers (1)

Floki
Floki

Reputation: 261

For POST request:

If you are sending POST request, use the following code on the server side like:

string sEcho = Request.Params["draw"];
int iDisplayStart = Convert.ToInt32(Request.Params["start"]);
string searchValue = Request.Params["search[value]"];
int orderColumn = Convert.ToInt32(Request.Params["order[0][column]"]);
string orderDir = Request.Params["order[0][dir]"];

For GET request:

The following code is what I used before for GET request.

NameValueCollection nvc = HttpUtility.ParseQueryString(Request.Url.Query);
string sEcho = nvc["draw"];
int iDisplayStart = Convert.ToInt32(nvc["start"]);
string searchValue = nvc["search[value]"];
int orderColumn = Convert.ToInt32(nvc["order[0][column]"]);
string orderDir = nvc["order[0][dir]"];

Upvotes: 7

Related Questions