System.Web.Mvc.JsonResult'不包含'MaxJsonLength的定义

时间:2015-02-14 15:07:29

标签: c# json asp.net-mvc-4

我在Framework 4.5中的Visual Studio中有项目。

这是一个ASP.NET MVC 4 WebApllication。我正在使用JSON来获取大量数据。但是当我执行它时,它给了我错误:使用JSON JavaScriptSerializer进行序列化或反序列化时出错。字符串的长度超过maxJsonLength属性上设置的值。

所以,我想用这段代码修改max json长度:

 protected override JsonResult Json(object data, string contentType, System.Text.Encoding contentEncoding, JsonRequestBehavior behavior)
    {
        return new JsonResult()
        {
            Data = data,
            ContentType = contentType,
            ContentEncoding = contentEncoding,
            JsonRequestBehavior = behavior,
            MaxJsonLength = Int32.MaxValue 
        };
    }

但我不能,因为我在行中遇到错误** MaxJsonLength = Int32.MaxValue **

错误是:System.Web.Mvc.JsonResult'不包含'MaxJsonLength

的定义

我在控制器类中有这些引用:

  • 使用System;
  • 使用System.Collections.Generic;
  • 使用System.Linq;
  • 使用System.Web;
  • 使用System.Web.Mvc;
  • 使用WebserviceIPAD.Areas.Api.Models;
  • 使用System.Web.Script.Serialization;

但仍然收到错误:System.Web.Mvc.JsonResult'不包含'MaxJsonLength

的定义

任何人都知道我是否必须导入更多参考文献?

感谢。

enter image description here

2 个答案:

答案 0 :(得分:1)

Can I set an unlimited length for maxJsonLength in web.config?

可以在config中设置:

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

答案 1 :(得分:0)

我刚刚找到了解决方案。我已经创建了新项目,每个类和配置一次。并且毫无问题地知道我可以使用MaxJsonLength。

感谢每一位人士的建议。