Problem Statement:
The following exception (error) occurs in ASP.NET when AJAX calls are made to PageMethod using jQuery AJAX or ScriptManager
Error during serialization or deserialization using the JSON JavaScriptSerializer.
“The length of the string exceeds the value set on the maxJsonLength property.”
Below code that helped to resolve the issue. Instead of using JsonResult replaced it with Content Result and set the javaScriptSerializer with MAXJsonLength.
Code:
1 2 3 4 5 6 7 8 9 10 |
public ContentResult Sample() { JavaScriptSerializer serializer = new JavaScriptSerializer(); serializer.MaxJsonLength = Int32.MaxValue; // Whatever max length you want here var resultData = new {--- }; // Whatever value you are serializing ContentResult result = new ContentResult(); result.Content = serializer.Serialize(resultData); result.ContentType = "application/json"; return result; } |