1

I have a jQuery Datatable that renders 1500 rows at the client side. My User checks the rows and then I send the Ids of selected rows and save the data.

This is working fine for the first 1000 rows but any time more than that is checked the data does not seem to be getting posted - on Dev Tools the call to MVC controller shows a 500 internal server error but with a breakpoint on the method it doesn't get hit?

If I have 1000 rows selected the breakpoint gets hit and all 1000 ids are passed. Once I add 1 more row to be checked the breakpoint doesn't get hit but I see 500 internal server error on Dev Tools?

My code is below:

  $('#saveBtn').click(function () {
    var dataArr = [];
    var rows = $('tr.selected');
    var rowData = myTable.rows({ selected: true }).data();

    $.each($(rowData), function (key, value) {
      dataArr.push(value[0]); //Id is hidden in 1st column of the table
    });

    $.ajax({
      type: 'POST',
      url: '@Url.Action("SaveData", "MyController")',
      data: JSON.stringify(dataArr),
      contentType: 'application/json; charset=utf-8',
      success: function (data) {
        location.reload();
      },
      error: function () {
        sweetAlert("Error Occurred Saving");
        location.reload();
      },
    });
  });

My MVC Controller is pretty straight forward

[HttpPost]
public ActionResult SaveData(List<int> Ids)
{
  //private method that just calls to the DB and sets a flag to say that Id was checked
  SaveData(Ids);

  return new HttpStatusCodeResult(HttpStatusCode.OK);  
}

I have tried to add the below to my MVC Web config but I still dont get breakpoint hit when I select more than 1000

<system.web.extensions>
  <scripting>
    <webServices>
      <jsonSerialization maxJsonLength="2147483644"/>
    </webServices>
  </scripting>
</system.web.extensions>
17
  • 1
    Try setting the maxjsonlength property to a higher value. Thanks. Commented May 16, 2017 at 15:19
  • a higher value than what I have as 2147483644 - isn't that the max value it can be? Commented May 16, 2017 at 15:28
  • where you could set the collection size? seems like it is limited to 1000 Commented May 16, 2017 at 15:29
  • The value is correct. Where have you placed the breakpoint - in SaveData function? If so, could you post the code or check if it catches any error Commented May 16, 2017 at 15:33
  • really dumb question but do you have pagination enabled on your datatable? Commented May 16, 2017 at 15:35

2 Answers 2

1

Adding to your appSettings element in configuration overrides default max limit as ASP.NET rejects request if they contain more than 1000 elements due to security concerns.

https://msdn.microsoft.com/en-us/library/hh975440(v=vs.120).aspx

Sign up to request clarification or add additional context in comments.

Comments

1

One of the way we can resolve the issue is specifying the maxlength of the json result in the c#.
Example:-

jsonResult.MaxJsonLength = 999999999;
return  jsonResult

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.