I am using the autocomplete feature of jQuery. When I try to retrieve the list of more then 17000 records (each won't have more than 10 char length), it's exceeding the length and throws the error:
Exception information:
Exception type: InvalidOperationException
Exception message: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
Can I set an unlimited length for maxJsonLength
in web.config
? If not, what is the maximum length I can set?
I solved the problem adding this code:
If you are encountering this sort of issue in View, you can use below method to resolve that. Here Iused Newtonsoft package .
If you are using MVC 4, be sure to check out this answer as well.
If you are still receiving the error:
maxJsonLength
property to its maximum value in web.configyour problem is is likely that:
Basically, the "internal"
JavaScriptSerializer
respects the value ofmaxJsonLength
when called from a web method; direct use of aJavaScriptSerializer
(or use via an MVC action-method/Controller) does not respect themaxJsonLength
property, at least not from thesystemWebExtensions.scripting.webServices.jsonSerialization
section of web.config.As a workaround, you can do the following within your Controller (or anywhere really):
This answer is my interpretation of this asp.net forum answer.
You can configure the max length for json requests in your web.config file:
The default value for maxJsonLength is 102400. For more details, see this MSDN page: http://msdn.microsoft.com/en-us/library/bb763183.aspx
If you are getting this error from the MiniProfiler in MVC then you can increase the value by setting the property
MiniProfiler.Settings.MaxJsonResponseSize
to the desired value. By default, this tool seems to ignore the value set in config.Courtesy mvc-mini-profiler.
if, after implementing the above addition into your web.config, you get an “Unrecognized configuration section system.web.extensions.” error then try adding this to your web.config in the
<ConfigSections>
section: