【问题标题】:Telerik MVC Grid - Multiple data rows resultTelerik MVC Grid - 多数据行结果
【发布时间】:2012-08-01 07:24:39
【问题描述】:

我正在使用 Telerik 网格来显示来自 sql db 的数据...当我显示超过 3500 行时,它返回:使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错。字符串长度超过 maxJsonLength 属性设置的值。

互联网上的任何地方和Telerik Troubleshooting manual 也写了这个原因是编辑web.config。这对我没有帮助...我尝试像这样返回数据:

JavaScriptSerializer serializer = new JavaScriptSerializer { MaxJsonLength = 536870912, RecursionLimit = 100 };
return new ContentResult()
{
    Content = serializer.Serialize(data),
    ContentEncoding = Encoding.UTF8
};

当我将数据作为 ContentResult 返回时,过滤和排序停止工作。

我也在尝试这个解决方案:http://anyrest.wordpress.com/2011/09/27/large-json-result-for-teleriks-mvc-grid/,但这对我没有帮助......

这是来自我的控制器的代码:

[GridAction, POST("GridData")]
public ActionResult _Index()
{
    var data = GetExclusionsDataCollection();
 
    return View(new GridModel { Data = data });
}

谢谢, 大卫

【问题讨论】:

    标签: asp.net-mvc json serialization telerik telerik-grid


    【解决方案1】:

    我联系了 Telerik 支持,现在我可以分享我的问题的原因...

    Telerik 代码库有 link。重要的部分是在 global.asax.cs 中添加行。他们解决方案的这一部分不在我见过的大多数其他解决方案中......

    DI.Current.Register<IGridActionResultFactory>(() => new MyCustomGridActionResultFactory());
    

    此行会导致 ovveride 默认 Telerik 功能并激活您的自定义 Json 结果...

    -大卫

    【讨论】:

      【解决方案2】:

      尝试增加 web.config 中的 maxRequestLength

      <system.web>
      <httpRuntime requestValidationMode="2.0" maxRequestLength="VALUE" />
      </system.web>
      

      其中 Value 将设置为 int.maxvalue 或 int64.maxvalue

      【讨论】:

        猜你喜欢
        • 2016-05-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多