字符串的长度超过maxJsonLength属性上设置的值。 在MVC3中
MVC3(.cshtml文件)
$.getJSON(URL, Data, function (data) { document.getElementById('divDisplayMap').innerHTML = data; if (data != null) { $('#myTablesId').show(); tdOnclickEvent(); } else { $('#myTablesId').hide(); } }).error(function (xhr, ajaxOptions, thrownError) { debugger; });
在服务器端
public JsonResult ZoneType_SelectedState(int x_Id, int y_Id) { JsonResult result = new JsonResult(); result.Data = "LongString";//Longstring with the length mention below return Json(result.Data,"application/json", JsonRequestBehavior.AllowGet); }
从服务器端我传递的字符串长度为1194812并且超过了。 但我得到的错误说
"Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property."
请帮帮我ASP
您可以编写一个自定义ActionResult,它允许您指定序列化程序可以处理的最大数据长度:
public class MyJsonResult : ActionResult { private readonly object data; public MyJsonResult(object data) { this.data = data; } public override void ExecuteResult(ControllerContext context) { var response = context.RequestContext.HttpContext.Response; response.ContentType = "application/json"; var serializer = new JavaScriptSerializer(); // You could set the MaxJsonLength to the desired size - 10MB in this example serializer.MaxJsonLength = 10 * 1024 * 1024; response.Write(serializer.Serialize(this.data)); } }
然后使用它:
public ActionResult ZoneType_SelectedState(int x_Id, int y_Id) { string data = "LongString";//Longstring with the length mention below; return new MyJsonResult(data); }
尝试更新您的Controller
方法,如下所示:
public JsonResult ZoneType_SelectedState(int x_Id, int y_Id) { var result = Json("LongString", JsonRequestBehavior.AllowGet); result.MaxJsonLength = int.MaxValue; return result; }
希望这可以帮助…
- 如何在剃刀视图上创建一个字段?
- 我试图在我的MVC ASP.NET应用程序中找到一个构建CSS字符串的解决方案,请问?
- MVC3 Razor Html.TextBoxFor计算字段
- MVC 3 Ajax.ActionLink与JQuery UI确认对话框
- jQuery datepicker的dateFormat – 如何与.NET当前文化DateTimeFormat集成
- 使用mvc 3 razor cshtml中的konckout.js创建一个带按钮的网格
- 使用jquery.load将对象数组传递给MVC 3
- jquery mobile ajax发送GET和POST请求
- JQuery Datepicker不会发布英国日期字符串