(未測試)原来MVC框架内置的JsonResult代码中,在使用JavaScriptSerializer时,都是采用的默认值,没有从maxJsonLength读取值,即忽略了这个配置。
在控制器中添加两个JsonResult,然后在需要返回大数据json的action调用,即用return LargeJson()代替return Json()
public JsonResult LargeJson(object data) { return new System.Web.Mvc.JsonResult() { Data = data, MaxJsonLength = Int32.MaxValue, }; } public JsonResult LargeJson(object data,JsonRequestBehavior behavior) { return new System.Web.Mvc.JsonResult() { Data = data, JsonRequestBehavior = behavior, MaxJsonLength = Int32.MaxValue }; }