错误字符串的长度超过了 maxJsonLength 属性上设置的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16848289/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 19:49:16  来源:igfitidea点击:

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

jsonkendo-grid

提问by Spidey

I am currently have a grid with PDF attachment. Each PDF can have file size up to 1MB. The problem is I am getting the value "Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property"

我目前有一个带有 PDF 附件的网格。每个 PDF 的文件大小最高可达 1MB。问题是我得到了值“使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错。字符串的长度超过了 maxJsonLength 属性上设置的值

I already placed the following in the web.config but the problem is it works only if the Kendo UI Grid needs to display 6 records.

我已经在 web.config 中放置了以下内容,但问题是它仅在 Kendo UI Grid 需要显示 6 条记录时才有效。

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

回答by Spidey

Based on the following link:

基于以下链接:

MaxJsonLength exception in ASP.NET MVC during JavaScriptSerializer

JavaScriptSerializer 期间 ASP.NET MVC 中的 MaxJsonLength 异常

public ActionResult SomeControllerAction()
{
  var jsonResult = Json(veryLargeCollection, JsonRequestBehavior.AllowGet);
  jsonResult.MaxJsonLength = int.MaxValue;
  return jsonResult;
}