期间的JavaScriptSerializer除了MaxJsonLength在ASP.NET MVC [英] MaxJsonLength exception in ASP.NET MVC during JavaScriptSerializer

查看:218
本文介绍了期间的JavaScriptSerializer除了MaxJsonLength在ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的控制器动作之一,我返回一个非常大的 JsonResult 来填充网格。

In one of my controller actions I am returning a very large JsonResult to fill a grid.

我收到以下出现InvalidOperationException 例外:

使用JSON序列化的JavaScriptSerializer反序列化或过程中的错误。字符串的长度超过上maxJsonLength属性设置的值。

的web.config 为较高的值设置 maxJsonLength 属性遗憾的是不显示任何效果。

Setting the maxJsonLength property in the web.config to a higher value unfortunately does not show any effect.

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

我不希望它传回一个字符串作为<一提到href=\"http://stackoverflow.com/questions/4155014/json-asp-net-mvc-maxjsonlength-problem/4155077#4155077\">this SO回答。

在我的研究,我碰到<一个href=\"http://thoughtful$c$c.word$p$pss.com/2011/01/03/custom-jsonresult-class-for-asp-net-mvc-to-avoid-maxjsonlength-exceeded-exception/\">this博客帖子里写一个自己的的ActionResult (例如 LargeJsonResult:JsonResult )。建议绕过此行为

In my research I came across this blog post where writing an own ActionResult (e.g. LargeJsonResult : JsonResult) is recommended to bypass this behaviour.

这是那么唯一的解决办法?结果
这是在ASP.NET MVC中的错误?结果
我缺少的东西吗?

Is this then the only solution?
Is this a bug in ASP.NET MVC?
Am I missing something?

任何帮助将是最AP preciated。

Any help would be most appreciated.

推荐答案

看来这已被固定在MVC4。

It appears this has been fixed in MVC4.

您可以做到这一点,这对我来说效果很好:

You can do this, which worked well for me:

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

这篇关于期间的JavaScriptSerializer除了MaxJsonLength在ASP.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆