MVC control中返回json格式数据一般都是如下格式
[HttpPost] public ActionResult CaseAudit(string name) { var data ="dasda"; return Json(data); }
但是这样如果字符串长度太大会报错
JSON JavaScriptSerializer 进行序列化或反序列化时出错。字符串的长度超过了为 maxJsonLength 属性设置的值
按下面方法可以解决
[HttpPost] public ActionResult CaseAudit(string name) { var data ="dasda"; return new JsonResult() { Data = data, MaxJsonLength = int.MaxValue, ContentType = "application/json" }; }
或者在Web.config中配置
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="1024000000" />
</webServices>
</scripting>
</system.web.extensions>