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

后端 未结 3 1964
没有蜡笔的小新
没有蜡笔的小新 2020-12-03 09:55

I am loading tab content data through jQuery\'s ajax post method via web method with around 200-300 records. And getting following error in the console:

3条回答
  •  误落风尘
    2020-12-03 10:50

    I know this is a very old thread at the time of my reading, and that WebMethod is not really a thing in ASP.NET MVC so this is somewhat tangential. But, if anyone runs across it -

    If you use ASP.NET MVC There is an alternative to invoking JavaScriptSerializer directly, which is to initialize the JsonResult and set the MaxJsonLength property on the result itself:

        private JsonResult GetReallyBigJsonResult(object data, JsonRequestBehavior requestBehavior)
        {
                return new JsonResult()
                {
                    ContentEncoding = Encoding.Default,
                    ContentType = "application/json",
                    Data = data,
                    JsonRequestBehavior = requestBehavior,
                    MaxJsonLength = int.MaxValue
                };
    
        }
    

提交回复
热议问题