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
Having model-binding with more than 4 MB of data.
A server exception is thrown.
The MaxJsonLength to be configured so that binding works as expected.
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 };