使用mvc jsonresult返回json对象 报错 maxjsonlength超长

解决办法:
1.放弃用jsonresult对象 ,使用json字符串传输,前端通过js再转化为json对象 $.parseJson();
2.重写jsonresult
来源:http://www.xuebuyuan.com/429710.html
class ConfigurableJsonResult : JsonResult
{
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
if (JsonRequestBehavior == JsonRequestBehavior.DenyGet &&
String.Equals(context.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
{
throw new InvalidOperationException("This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet.");
}
HttpResponseBase response = context.HttpContext.Response;
if (!String.IsNullOrEmpty(ContentType))
{
response.ContentType = ContentType;
}
else
{
response.ContentType = "application/json";
}
if (ContentEncoding != null)
{
response.ContentEncoding = ContentEncoding;
}
if (Data != null)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
ScriptingJsonSerializationSection section = ConfigurationManager.GetSection("system.web.extensions/scripting/webServices/jsonSerialization") as ScriptingJsonSerializationSection;
if (section != null)
{
serializer.MaxJsonLength = section.MaxJsonLength;
serializer.RecursionLimit = section.RecursionLimit;
}
response.Write(serializer.Serialize(Data));
}
}
}

浙公网安备 33010602011771号