如何设置maxJsonLength属性? [英] How to set the maxJsonLength property?
问题描述
我有一个JsonResult返回29833条记录,包含CustomerID和CustomerName。我试图将其加载到自动完成,但我不断收到此错误。
I have a JsonResult returning 29833 records, of a CustomerID and a CustomerName. I am trying to load this into an AutoComplete, but I keep getting this error.
使用JSON JavaScriptSerializer进行序列化或反序列化时出错。字符串的长度超过了maxJsonLength属性上设置的值。
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
我在这个主题上做了一些挖掘并遇到了这个链接此处
所以我读了它并且提供的答案对我来说没有用,然后下一个建议看起来很有希望,直到我看了更多代码并得出结论它对我不起作用因为我正在使用获取JsonResult的JQuery Ajax。现在我不知道该怎么做,这是我正在使用的JQuery
I did some digging around on the subject and came across this link here
So I read over it and the answer provided didn't work out for me and then the next suggestion looked promising until I looked more at the code and came to the conclusion that it won't work for me because I am using JQuery Ajax to get the JsonResult. Now I am not sure what to do, here is the JQuery that I am using
function LoadCustomers() {
$.ajax({
type: "GET",
url: "/Test/GetAllCustomers",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data, textStatus, jqXHR) {
ShowCustomers(data);
}
});
}
function ShowCustomers(custdata) {
$("#acCustomers").kendoAutoComplete({
dataSource: custdata,
filter: "startswith",
placeholder: "Select Customer...",
dataTextField: "CustomerName"
});
}
我甚至尝试过填充网格但无济于事。任何关于如何让我按照我的方式正常工作的想法?我认为作为最后的手段,我将不得不改变我的存储过程并在每个keyup事件中传递字符,我不知道这是不是一个好主意或者可能是,我不知道。无论哪种方式,我肯定可以使用一些帮助或方向
I even tried just populating a grid but to no avail. Any idea's on how I can get this to work properly going about it the way I am going about it? I think as a last resort I would have to change my stored procedure around and pass in characters on every keyup event, I don't know if that would be a good idea or maybe it is, I don't know. Either way I sure could use some help or direction
编辑
根据提供的链接,这不是重复的原因是因为我不在服务器端,我在客户端工作。
EDIT The reason that this is not a duplicate based on the supplied link is because I am not working server-side, I am working Client-Side.
编辑2
这是我的JsonResult
Here is my JsonResult
public JsonResult GetAllCustomers(string name)
{
PGDAL dal = new PGDAL();
List<Customer> lst = dal.GetAllCustomers();
return Json(lst, JsonRequestBehavior.AllowGet);
}
推荐答案
我从中学到了一件事一些经验是,似乎ASP.net MVC忽略了您放在Web.config文件中的任何JSON Max值。我通常只是执行以下操作:
One thing I have learned from some experience is that it seems like ASP.net MVC ignores any JSON Max value you place in the Web.config file. I normally just do the following:
var JsonSerializer = new JavaScriptSerializer();
JsonSerializer.MaxJsonLength = Int32.MaxValue;
当Paul Swetz联系起来时,您可能会在管理MAX值方面找到更多资源但我是很确定这将是最广泛接受的答案。
As Paul Swetz linked up top, you might find some more resources in managing the MAX value but I am pretty sure this will be the most widely accepted answer.
这篇关于如何设置maxJsonLength属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!