System.Web.Mvc.JsonResult”不包含“MaxJsonLength”的定义
System.Web.Mvc.JsonResult' does not contain a definition for 'MaxJsonLength
我在 Framework 4.5 的 Visual Studio 中有一个项目。
它是一个 ASP.NET MVC 4 WebApllication。我正在使用 JSON 获取大量数据。但是当我执行它时,它给了我那个错误:使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错。字符串长度超过maxJsonLength设置的值属性.
所以,我想用这段代码修改最大 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
的定义
我在控制器的 class 中有这些引用:
- 使用系统;
- 使用 System.Collections.Generic;
- 使用 System.Linq;
- 使用 System.Web;
- 使用 System.Web.Mvc;
- 使用 WebserviceIPAD.Areas.Api.Models;
- 使用 System.Web.Script.Serialization;
但仍然出现错误:System.Web.Mvc.JsonResult' does not contain a definition for 'MaxJsonLength
有人知道我是否需要导入更多参考文献吗?
谢谢。
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>
我刚刚找到了解决方案。我创建了新项目,每 类 和配置一次。并且知道我可以毫无问题地使用 MaxJsonLength。
谢谢大家的建议。
我在 Framework 4.5 的 Visual Studio 中有一个项目。
它是一个 ASP.NET MVC 4 WebApllication。我正在使用 JSON 获取大量数据。但是当我执行它时,它给了我那个错误:使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错。字符串长度超过maxJsonLength设置的值属性.
所以,我想用这段代码修改最大 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
的定义我在控制器的 class 中有这些引用:
- 使用系统;
- 使用 System.Collections.Generic;
- 使用 System.Linq;
- 使用 System.Web;
- 使用 System.Web.Mvc;
- 使用 WebserviceIPAD.Areas.Api.Models;
- 使用 System.Web.Script.Serialization;
但仍然出现错误:System.Web.Mvc.JsonResult' does not contain a definition for 'MaxJsonLength
有人知道我是否需要导入更多参考文献吗?
谢谢。
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>
我刚刚找到了解决方案。我创建了新项目,每 类 和配置一次。并且知道我可以毫无问题地使用 MaxJsonLength。
谢谢大家的建议。