0

I am attempting to pass a json object in the data: JSON.stringify(dataObj) of a ajax call and I am never getting to the ajax destination of my MVC Controller. It works perfectly with smaller sized versions of the object. This only occurs when passing to the controller vs. returning from in which I do this: enter image description here

Here is my script: enter image description here

Need a little guidance here. Nothing seems to fix this.

mwilson
  • 12,295
  • 7
  • 55
  • 95
Dan Colgan
  • 21
  • 3
  • 3
    Post your code as text and not as a picture – Aalexander Feb 05 '21 at 18:54
  • Yes, and it would also be nice if you explicitly said what programming language that first block is. – Pointy Feb 05 '21 at 18:55
  • Does this answer your question? [the length of the string exceeds the value set on the maxjsonlength property in mvc](https://stackoverflow.com/questions/45769035/the-length-of-the-string-exceeds-the-value-set-on-the-maxjsonlength-property-in) – mwilson Feb 05 '21 at 19:23

1 Answers1

0

You are hitting the max size of your json payload so your serializer is throwing an exception. This doesn't have anything to do with your JavaScript, it's all in your backend.

You need to set the MaxJsonLength property on your JavaScriptSerializer settings

The maximum length of JSON strings. The default is 2097152 characters, which is equivalent to 4 MB of Unicode string data.

Example: serializer.MaxJsonLength = <something big enough to support your payload>;

If that still doesn't work, update your web.config with something similar:

<configuration> 
   <system.web.extensions>
       <scripting>
           <webServices>
               <jsonSerialization maxJsonLength="50000000"/>
           </webServices>
       </scripting>
   </system.web.extensions>
</configuration>

It may also help to determine how big your payload actually is before returning it.

https://learn.microsoft.com/en-us/dotnet/api/system.web.script.serialization.javascriptserializer.maxjsonlength?view=netframework-4.8

mwilson
  • 12,295
  • 7
  • 55
  • 95