0

I have been working on this Issue for quite some time now. Basically, I'm using Kendo Grid to display data from Controller to the ViewPage.

But, when I run the view, I Keep getting this error maxJsonLengthError

How do i rectify this problem?? Appreciate all the help in advance. Refer to my EDIT

Here is my ControllerCode:-

public ActionResult Index()
{
    ViewData["DealsList"] = objDealerModel.listDeals;
    return View();
}

And Here is my ViewPage Code:-

@(Html.Kendo().Grid((IEnumerable<WCB.Models.DealerQueue>)ViewData["DealsList"])
        .Name("Grid")
        .Columns(columns =>
        {
            columns.Bound(p => p.DealId).Visible(false);
            columns.Bound(p => p.DealRefNo).Title("Deal No");
            columns.Bound(p => p.CustomerName).Title("Customer Name");
            columns.Bound(p => p.DealType).Title("Deal Type");
            columns.Bound(p => p.Location).Visible(false);
            columns.Bound(p => p.CreatedDate).Title("Created Date");
            columns.Bound(p => p.Currency).Title("Currency");
            columns.Bound(p => p.Amount).Title("FCY Amount");
            columns.Bound(p => p.DealValue).Title("Deal Amount").ClientTemplate("#= kendo.toString(DealValue, 'n') #");
            columns.Bound(p => p.Status);
            columns.Command(command => command.Custom("ViewDetails").Click("ViewDealDetails")).Title("View");
        })
                .Pageable(pageable => pageable
                .Refresh(true)
                .PageSizes(true)
                .ButtonCount(20))
        .Sortable()
        .Scrollable(scr => scr.Height("auto"))
        .Filterable()
        .DataSource(dataSource => dataSource
        .Ajax()
        .ServerOperation(false)
    )

)

EDIT: i've tried using this piece of code in myController:-

var jsonResult = Json(objDealerModel.listDeals, JsonRequestBehavior.AllowGet);
jsonResult.MaxJsonLength = int.MaxValue;
return jsonResult;

Can anyone suggest based on this what changes need to be made in my viewPage for KENDO GRID?? Not too familiar with Kendo

  • Just hava a look at [**this**](http://stackoverflow.com/a/7207539/3814721) – mmushtaq Apr 12 '17 at 04:45
  • 1
    Refer [this answer](http://stackoverflow.com/questions/5692836/maxjsonlength-exception-in-asp-net-mvc-during-javascriptserializer). But basically your sending too much data to the view (and no one would be able to absorb that much information. –  Apr 12 '17 at 04:45
  • @StephenMuecke, tried using var jsonResult = Json(objDealerModel.listDeals, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; any idea on how my viewPage should change based on this?? – reizonShrestha Apr 12 '17 at 07:06

1 Answers1

0

I have a same problem and i solve this by setting a higher value for aspnet:MaxJsonDeserializerMembers in the appSettings:

<appSettings>
  <add key="aspnet:MaxJsonDeserializerMembers" value="150000" />
</appSettings>

If those options are not working you could try creating a custom json value provider factory using JSON.NET as specified in this thread.

Edit: Or if this is related to the Kendo Grid binding then you can try this.

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() );
Community
  • 1
  • 1
Shahzad
  • 1,315
  • 2
  • 22
  • 42
  • i think the problem is with Kendo not being able to bind the data to the Grid, because when i pass data as Json without trying to bind the data to Kendo Grid, then i can get the JsonResult – reizonShrestha Apr 12 '17 at 08:05
  • then i think this [link](http://www.telerik.com/forums/another-maxjsonlength-issue) will be helpful for you. – Shahzad Apr 12 '17 at 08:08
  • or maybe this [link](https://github.com/telerik/kendo-ui-core/issues/2667), direct from kendo UI Core. – Shahzad Apr 12 '17 at 08:10
  • @reizonShrestha i have updated the answer for binding the max data with the kendo grid. – Shahzad Apr 12 '17 at 08:24