1、Web.config
網上大部分的解決方案爲
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483644" />
</webServices>
</scripting>
</system.web.extensions>
或許是我的JSON還是太長,這個解決方案並未起作用。
2、從返回值方面修改(推薦)
將原本返回的JsonResult改爲ActionResult,真正返回時返回ContentResult
代碼如下:
var serializer = new JavaScriptSerializer();//使用原生Json轉換類
serializer.MaxJsonLength = Int32.MaxValue;
var result = new ContentResult
{
Content = JsonConvert.SerializeObject(list),// serializer.Serialize(list), //data爲要序列化的LINQ對象
ContentType = "application/json"
};return result;
或:
ContentResult result = new ContentResult
{
Content = JsonConvert.SerializeObject(list),//serializer.Serialize(list), //data爲要序列化的LINQ對象
ContentType = "application/json"
};
return result;