0

I get the following error when playing with JSON request:

Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.

This is the jQuery code:

//load partial view contain grid
$('#rptProductsRates').load('@Url.Action("ProductsRatesFlipPagination", "Reports")', { flipPagination: true }, function (data) {
    if (data.toString().substr(0, 15) == "<!DOCTYPE html>") {
      window.location = '@Url.Action("ProductsRates", "Reports")';
    }    
    else {
            debugger;
            var resultError = data.toString().substr(0, 9);
            if (resultError == "<!DOCTYPE") {
               var exceptionURL='@Url.Content("~/Reports/Exception?controller=Reports&action=ProductsRates")';
                        window.location = exceptionURL;
                //unblock the UI     
                $.unblockUI();
            }
            else {
                $('#contentDiv').show();
                //unblock the UI     
                $.unblockUI();
                var bottomMarginFirst = (screen.height * .29)
                var bottomMargin = (screen.height * .42)
                if ($('.renderBody').height() <= ($(document).height() - bottomMarginFirst)) {
                    $('.renderBody').css({ 'height': ($(document).height() - bottomMargin + @System.Configuration.ConfigurationManager.AppSettings["GridHeight"] - 100) })
                }
            }
    }

What's the cause and a possible solution to this error?

Shef
  • 44,808
  • 15
  • 79
  • 90
user584018
  • 10,186
  • 15
  • 74
  • 160

1 Answers1

0

Looks like you're throwing an AJAX request back to a an ASP.NET MVC3 back-end. AFAIK, the native Javascript serializer used by MVC3 has a default maximum parsed JSON length of 4MB (correct me if I'm mistaken). If you're passing in a JSON string larger than that, you'll have to slap on a workaround (by breaking up the request, optimizing your objects, or tweaking your server-side settings).

Richard Neil Ilagan
  • 14,627
  • 5
  • 48
  • 66
  • yes you are correct, from back end I have 6885 records and with 15 columns. I think 4MB thing applies here...Is there any way to check and the size of JSON string?? – user584018 Sep 29 '11 at 11:02
  • Not really sure how to do that, but with a data payload of that size, I'd say you're definitely going over. If you're not performing a data buffet, you may want to probably consider AJAX request pooling? Pull out the records in sequential batches across multiple AJAX calls. – Richard Neil Ilagan Sep 29 '11 at 11:07
  • link is, http://anyrest.wordpress.com/2011/09/27/large-json-result-for-teleriks-mvc-grid/ – user584018 Oct 01 '11 at 16:19