1

I have a the following code

ajax call

$.ajax({
type: "POST",
dataType: "json",
async: false,
contentType: "application/json; charset=utf-8",
url: "Account/SomeFunc",
data: JSON.stringify(dataToSend),

success: function (res) {
//some code

},

error: function (res, textStatus, errorThrown) {
//some code

}
});

and on the server-side

public ActionResult SomeFunc()
    {
        //some code
        VeryBigObject result = getResult();

        if (result == null)
            return null;

        var jsonResult = Json(result, JsonRequestBehavior.AllowGet);
        jsonResult.MaxJsonLength = int.MaxValue;

        return jsonResult;
    }

result variable can be small but sometimes its a very big object. when the object is small enough the code works and the ajax success code is activated but when the result is big enough the code fails with 500 Internal Server Error. I cant put MaxJsonLength any bigger because its an int but sometimes I need to send some big data.. what can I do?

Adam
  • 464
  • 6
  • 16

2 Answers2

2

Use the code below in web.config. It will solve your problem.

<system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="900000" />
      </webServices>
    </scripting>
 </system.web.extensions>
Siddesh
  • 161
  • 7
0

Increasing maxJsonLength in Web config worked for me when I faced similar issues with large json data.

inan
  • 178
  • 11