We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Script error throws for exceeding maxJsonLength while performing serialization or deserialization

 

 

 

Problem:

 

While binding very large data to the grid it throws a following exception.

 

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

 

Cause:

 

In our latest MVC grid, we have rendered all the html elements in client side and we have passed the data to the control from server side to client side as Json data by serializing it.

 

And we have used the default MaxJsonLength value (2097152 characters, which is equivalent to 4 MB of Unicode string data) of the JavaScriptSerializer which is a fixed universal standard length for serializing the data.

Solution:

 

1. By Serializing the JSON data

 

Serialize the JSON data before send the response from server side. Please refer to the following response for avoiding the MaxJsonLength serialization issue, 

https://stackoverflow.com/questions/1151987/can-i-set-an-unlimited-length-for-maxjsonlength-in-web-config/#25413043

https://stackoverflow.com/questions/1151987/can-i-set-an-unlimited-length-for-maxjsonlength-in-web-config/#7807964

 

2. Using WebMethodAdaptor

 

Use WebMethodAdaptor to bound the Grid datasource. Use the WebMethodAdaptor to get the data from the controller through post action and bound the Json result as a grid data source.

 

Aspx

 

 

C#

 

 

The result will be as follows.

 

C:\Users\renjithsingh.rajendr\AppData\Local\Microsoft\Windows\INetCache\Content.Word\webmethod.png

Figure 1: Shows the Grid rendered by binding data using WebMethodAdaptor.

Article ID: Published Date: Last Revised Date: Platform: Control: Product Version:
8573 03/08/2018 03/08/2018 ASP.NET Web Forms Grid 1.1.0.8
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.