0

I've had a look and I can't seem to get this to work and I constantly get the error message that my json object is too large to pass to my controller.

The length of the string exceeds the value set on the maxJsonLength property.

So I have a json object that contains the base64 string of up to 3 images as well as some textual data.

I am trying to pass that object to the controller. It works fine if I do not include the images.

So I have tried, in web.config;

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

as well as;

<add key="aspnet:MaxJsonDeserializerMembers" value="150000000" />

I have changed my controller from an ActionResult to a JsonResult.

I've read that I need to create my own json parser etc and a lot of the sites deal with passing data from the controller to the client.

I am trying to get a large amount of data from the client to the controller.

Any help here?

griegs
  • 22,624
  • 33
  • 128
  • 205
  • Changing `ActionResult` to `JsonResult` should not make any difference (that specifies the type of data that is sent from the controller to the view). Is there a reason you need to post your images as json rather than using `FormData`? –  Oct 26 '15 at 00:35
  • I can't use formdata as there is already a parent form that some bright spark created for [all] web pages a couple years ago and i do not have the scope to redesign all this spaghetti. – griegs Oct 26 '15 at 00:37
  • That should not stop you from using `FormData` to post your 3 files. - `var formdata = new FormData()` then append each of your files and post using the technique [shown here](http://stackoverflow.com/questions/29293637/how-to-append-whole-set-of-model-to-formdata-and-obtain-it-in-mvc/29293681#29293681) –  Oct 26 '15 at 00:40
  • OK, so the files were selected on another screen and are now in Base64 – griegs Oct 26 '15 at 00:41

1 Answers1

0

If you take a look at the source code ASP.NET MVC for the JsonResult class, you find this code (+):

if (Data != null)
{
    JavaScriptSerializer serializer = new JavaScriptSerializer();
    if (MaxJsonLength.HasValue)
    {
        serializer.MaxJsonLength = MaxJsonLength.Value;
    }
    if (RecursionLimit.HasValue)
    {
       serializer.RecursionLimit = RecursionLimit.Value;
    }
    response.Write(serializer.Serialize(Data));
}

The defualt values for MaxJsonLength property is set to 2MB and RecursionLimit is set to 100. You can change the defualt values this way:

return new JsonResult
{
     MaxJsonLength = Int32.MaxValue,
     Data = customers,
     JsonRequestBehavior = JsonRequestBehavior.AllowGet
};

more info.

Sirwan Afifi
  • 10,654
  • 14
  • 63
  • 110