Kendo-ui-core: Increase the DefaultJavaScriptSerializer.MaxJsonLength property to its maximum value

Created on 25 Jan 2017  路  8Comments  路  Source: telerik/kendo-ui-core

Bug report

In order to render bug amount of data through Model-binding users should be able to configure the MaxJsonLength value for the DefaultJavaScriptSerializer.

Ticket ID: 1085906

Reproduction of the problem

Having model-binding with more than 4 MB of data.

Current behavior

A server exception is thrown.

Expected/desired behavior

The MaxJsonLength to be configured so that binding works as expected.

Environment

  • Kendo UI version: all
  • jQuery version: all
  • Browser: [all]
Bug Wrappers (ASP.NET MVC) High jQuery1

All 8 comments

Are we certain we'd like to change an application configuration setting from an UI component? What would happen if the developer has already set it to the desired value?

This is a workaround shared by the community, it may be used in these scenarios:

public class MySerializer : Kendo.Mvc.Infrastructure.JavaScriptInitializer
{
    public override IJavaScriptSerializer CreateSerializer()
    {
        var serializer = base.CreateSerializer() as DefaultJavaScriptSerializer;
        serializer.MaxJsonLength = serializer.MaxJsonLength * 100;
        return serializer;
    }
}

Kendo.Mvc.Infrastructure.DI.Current.Register<Kendo.Mvc.Infrastructure.IJavaScriptInitializer>( () => newMySerializer() );

I see what you mean, thanks! I've missed the "model binding" part initially.

As the MaxJsonLength property cannot be changed from the Web.config in certain cases:

we decided to increase it to its maximum value (Int32.Max) by default.

If you need to make any additional configurations, you can use the above approach with custom JavaScriptSerializer. In addition, the MVC wrappers for ASP.NET Core use the Json.NET serializer (which doesn't have such issues), so we can switch to it in the future.

@simonssspirit where do you have to include this code (work around)? can you show with example? will be really helpfull. Thanks.

@atif7 This code can be added either in the Controller or in an upper base Controller.

Yes thanks, I figured it out :)

Hl use this return value
return new JsonResult() { Data = documentViewModelList.ToDataSourceResult(request), MaxJsonLength = Int32.MaxValue };

Was this page helpful?
0 / 5 - 0 ratings