简体   繁体   English

尝试将部分视图转换为字符串时,“字符串的长度超出了在maxJsonLength属性上设置的值。”

[英]“The length of the string exceeds the value set on the maxJsonLength property.” when trying to convert a partial view to string

I am getting the error "Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property." 我收到错误消息"Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property." when trying to convert a MVC partial view to string when the payload exceeds the MaxJsonLength property. 当有效载荷超过MaxJsonLength属性时尝试将MVC部分视图转换为字符串时。

How do I go about setting the MaxJsonLength property in this case? 在这种情况下,如何设置MaxJsonLength属性? I've tried setting the <jsonSerialization maxJsonLength="2147483644"/> property in the web.config, as per this post, but that doesn't have any effect. 我已经尝试设置<jsonSerialization maxJsonLength="2147483644"/>属性在web.config中,按照这个帖子,但没有任何效果。 I am not entirely where to go from here and looking for a bit of a guidance. 我不完全是从这里去寻找指导的地方。

The code errors on the viewResult.View.Render(viewContext, sw); viewResult.View.Render(viewContext, sw);上的代码错误viewResult.View.Render(viewContext, sw); line below: 下面的行:

    protected string ConvertViewToString(string viewName, object model)
    {
        string razorView = string.Empty;

        if (string.IsNullOrWhiteSpace(viewName)) return razorView;

        if (model != null && ViewData != null)
        {
            ViewData.Model = model;
        }

        if (ControllerContext != null)
        {
            ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
            if (viewResult != null)
            {
                using (StringWriter sw = new StringWriter())
                {
                    ViewContext viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);

                    viewResult.View.Render(viewContext, sw);
                    viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View);

                    razorView = sw.GetStringBuilder().ToString();
                }
            }
        }

        return razorView;
    }

The underlying cause of this was due to trying to load too large a result set into the Telerik Kendo grid within the partial view - the Kendo grid was throwing the exeception which is why it was being caught on the viewResult.View.Render(viewContext, sw) line. 造成这种情况的根本原因是由于试图将太大的结果集加载到部分视图中的Telerik Kendo网格中-Kendo网格引发了误解,这就是为什么它被捕获在viewResult.View.Render(viewContext, sw)行。 The solution was to break the result set down into smaller manageable chunks. 解决方案是将结果集分解为较小的可管理块。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误“字符串的长度超过了 maxJsonLength 属性上设置的值。” - Error 'The length of the string exceeds the value set on the maxJsonLength property.' 字符串的长度超过maxJsonLength属性上设置的值 - length of the string exceeds the value set on the maxJsonLength property 字符串的长度超过maxJsonLength属性c上设置的值。 - The length of the string exceeds the value set on the maxJsonLength property.c# 字符串的长度超过了 mvc 中 maxjsonlength 属性上设置的值 - the length of the string exceeds the value set on the maxjsonlength property in mvc MVC4错误:字符串的长度超过了在maxJsonLength属性上设置的值 - MVC4 error: The length of the string exceeds the value set on the maxJsonLength property 正在检测字符串的长度超过在服务器上的maxJsonLength属性上设置的值 - Detecting The length of the string exceeds the value set on the maxJsonLength property at the server 我收到“字符串的长度超过 maxJsonLength 属性上设置的值” - I am getting a “The length of the string exceeds the value set on the maxJsonLength property” JavaScript中View转换ViewBag.JsonData时,得到 The length of the string exceeds the value set on the maxJsonLength property - While converting ViewBag.JsonData from View in JavaScript, getting The length of the string exceeds the value set on the maxJsonLength property 使用JSON JavaScriptSerializer时发生错误“字符串的长度超过了在maxJsonLength属性上设置的值” - Error when using JSON JavaScriptSerializer “The length of the string exceeds the value set on the maxJsonLength property” ASP.Net WebForm c#Web服务-字符串的长度超过在maxJsonLength属性上设置的值 - ASP.Net WebForm c# WebService - The length of the string exceeds the value set on the maxJsonLength property
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM