Today, the customer suddenly came to me to say that in the background to add an extra long article, all the background of the article is not displayed. The front-end display is Easyui, and the returned data is all in JSON. Following the same operation according to the customer's description, an error occurred during the firebug of the Ajax returned exception "serialization or JSON JavaScriptSerializer. The length of the string exceeds the value set on the Maxjsonlength property "
This exception is thrown when executing the jsonresult in MVC, and according to the message of the exception, the serialized string exceeds the maxjsonlength limit. and learned that this attribute is provided by JavaScriptSerializer, because the MVC built-in Jsonresult is serialized with JavaScriptSerializer. A quick search on the Internet, encountered many of this problem, most of the recommended solution is to add the following configuration in Web. config, set the length of the Maxjsonlength
1 <system.web.extensions>2 <Scripting>3 <webservices>4 <jsonserializationMaxjsonlength= "102400"/>5 </webservices>6 </Scripting>7 </system.web.extensions>
Then change the size of the maxjsonlength as needed
Works fine, but the problem remains, and no matter how much maxjsonlength is set to be invalid
No way, can only continue to search for information.
Originally the MVC framework built-in Jsonresult code, when using JavaScriptSerializer, are the default values, not read from the Maxjsonlength value, that is, ignore this configuration.
Finally found the answer on the StackOverflow.
Add two Jsonresult to the controller and then use return Largejson () instead of return JSON () in the action call that needs to return the Big Data JSON ()
PublicJsonresult Largejson (Objectdata) { return NewSystem.Web.Mvc.JsonResult () {Data=data, Maxjsonlength=Int32.MaxValue,};} PublicJsonresult Largejson (Objectdata,jsonrequestbehavior behavior) { return NewSystem.Web.Mvc.JsonResult () {Data=data, Jsonrequestbehavior=behavior, Maxjsonlength=Int32.MaxValue};}
Specific website: http://stackoverflow.com/questions/4155014/json-asp-net-mvc-maxjsonlength-exception
Said here have to sigh
A lot of technical problems, Baidu came out of the results are no other foreign cattle, later encountered technical problems or Google point
ASP. NET MVC 4 JSON Big Data exception hint JSON character length exceeds limit exception