30

I am currently have a grid with PDF attachment. Each PDF can have file size up to 1MB. The problem is I am getting the value "Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property"

I already placed the following in the web.config but the problem is it works only if the Kendo UI Grid needs to display 6 records.

<system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength = "2147483647"></jsonSerialization>
      </webServices>
    </scripting>
</system.web.extensions>
Rap
  • 6,851
  • 3
  • 50
  • 88
Spidey
  • 1,583
  • 5
  • 23
  • 30
  • possible duplicate of [Can I set an unlimited length for maxJsonLength in web.config?](http://stackoverflow.com/questions/1151987/can-i-set-an-unlimited-length-for-maxjsonlength-in-web-config) – James Lawruk Sep 22 '13 at 13:53

1 Answers1

74

Based on the following link:

MaxJsonLength exception in ASP.NET MVC during JavaScriptSerializer

public ActionResult SomeControllerAction()
{
  var jsonResult = Json(veryLargeCollection, JsonRequestBehavior.AllowGet);
  jsonResult.MaxJsonLength = int.MaxValue;
  return jsonResult;
}
Community
  • 1
  • 1
Spidey
  • 1,583
  • 5
  • 23
  • 30
  • 2
    It would be nice that they set this up in config file so not to have to add the extra code here. Thanks! – Jason Foglia Mar 22 '16 at 15:59
  • Hello ! Here I'm getting error of exceeded max length when I post request with above 600 length of array list in json. I'm passing all data to controller. – SPnL Dec 22 '17 at 11:46