Can I set an unlimited length for maxJsonLength in web.config?

后端 未结 29 3255
礼貌的吻别
礼貌的吻别 2020-11-21 06:43

I am using the autocomplete feature of jQuery. When I try to retrieve the list of more then 17000 records (each won\'t have more than 10 char length), it\'s exceeding the le

29条回答
  •  滥情空心
    2020-11-21 07:36

    In MVC 4 you can do:

    protected override JsonResult Json(object data, string contentType, System.Text.Encoding contentEncoding, JsonRequestBehavior behavior)
    {
        return new JsonResult()
        {
            Data = data,
            ContentType = contentType,
            ContentEncoding = contentEncoding,
            JsonRequestBehavior = behavior,
            MaxJsonLength = Int32.MaxValue
        };
    }
    

    in your controller.

    Addition:

    For anyone puzzled by the parameters you need to specify, a call could look like this:

    Json(
        new {
            field1 = true,
            field2 = "value"
            },
        "application/json",
        Encoding.UTF8,
        JsonRequestBehavior.AllowGet
    );
    

提交回复
热议问题