Using the datatable on a Razor view page - sending the datatable data
Using the datatable on a Razor view page - sending the datatable data

Here is what I'm running into and wondering if others did this. I have a Razor web app using Razor Views. I have the datatable on a partial view. I do not have a form tag or submit button on my page. What I'm trying to do is, I want to send the selected rows in the datatable to my C# handler, however, I keep getting a 400 error. I do have the data formatted in JSON, I am able to send that, however, once it's gets to a certain number of rows, it gives the 400 or if I add 'POST' in my JQuery Ajax call, I get the 400 bad request errors. Is there a way to pass the DataTable in a JSON format to the code behind using JQuery and not hit limits? I run the JQuery on a button click but not a submit because I don't want to submit the entire form, only send the table data to the handler
Answers
The webserver might be erroring out because the URL is too long when using GET. You might be able to configure this. Refer to your webserver docs. Look at the webserver logs to get more info about why it’s responding with the 400 error.
Possibly you need to configure the webserver to accept the POST request. Refer to your webserver docs to learn how to support POST requests.
Kevin
I'm running this locally using Visual Studio. The GET works but to a point, which is if I select 16 rows that can have 4 data items each and the POST just kicks out the 400 no matter what. Guess I'll do some more digging
i'm not sure what language you are using for the webserver but if it's PHP then use the $_POST variable to get the parameters in the request. Otherwise refer to the docs of the webserver you are using with Visual Studio.
The process to retrieve GET parameters is different than POST parameters. You need to configure the "route" in the webserver to accept POST requests and parse the POST parameters.
Kevin
Definitely have a look at the length of the GET request. The number of rows won't effect the number of query parameters, but the number of columns will. As Kevin says, use
POST
(Request.Form
in C#) if the request is too long.Allan