Tuesday, December 24, 2013

MaxJsonLength exception

MaxJsonLength exception in ASP.NET MVC4 during JavascriptSerializer:

public ActionResult Index(){
    var data = null  //give some large data e.g big list of values
    var resultData = Json(data, JsonRequestBehavior.AllowGet);
    resultData.MaxJsonLength = Int32.MaxValue;
    return resultData;

Note: Then web.config setting is ignored by the default JsonResult implementation. So we might need to implement a custom Json Result or we can use the above code.