I have an MVC4 application using the Kendo Grid and I am trying to implement something similar to the example given here:
http://demos.telerik.com/kendo-ui/web/grid/local-data.html
The demo has a code snippet like this:
@model IEnumerable<Kendo.Mvc.Examples.Models.ProductViewModel>
@(Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.ProductName).Title("Product Name");
columns.Bound(p => p.UnitPrice).Title("Unit Price").Width(130);
columns.Bound(p => p.UnitsInStock).Title("Units In Stock").Width(130);
columns.Bound(p => p.Discontinued).Width(130);
})
.Pageable()
.Sortable()
.Scrollable(scr=>scr.Height(430))
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.ServerOperation(false)
)
)
and for the controller, like this:
using System.Web.Mvc;
namespace Kendo.Mvc.Examples.Controllers
{
public partial class GridController : Controller
{
public ActionResult Local_Data()
{
var model = productService.Read();
return View(model);
}
}
}
The grid in my application is bound from server side and would like to do the paging, sorting and etc from the client side once it's bound and displayed in the view. It is very much set up like the example given above. I tried to Google this hoping to get some tips and I stumbled upon this Telerik thread:
http://www.telerik.com/forums/grid-server-side-binding-and-client-side-paging-sorting-etc
The Telerik staff mentioned in this forum that "This can be achieved by setting DataSource ServerOperation setting to false and pass the data to the Grid constructor". So, I followed his advice and also followed the demo given, however, my grid is always failing and gives me an error about "maxJsonLength" property and JavaScript serializer. Any advice on how I go about this? I tried changing the maxJson length property in web.config, but that did not work.
So, is what I am trying to accomplish possible? Is there something I am missing? Thanks very much for your time and I look forward to the response(s).
Romel
12 Answers, 1 is accepted
Please take a look at the following documentation page, which describes the possible resolutions for the issue.
I hope this information helps.
Regards,
Dimiter Madjarov
Telerik

Romel

Hello Travis,
The issue is not related to the server binding of the Grid. Are you experiencing any difficulties with it?
Regards,Dimiter Madjarov
Telerik

@(Html.Kendo().Grid(Model.SearchResults)
...
.DataSource(dataSource => dataSource.Ajax().PageSize(10).ServerOperation(
false
))
I am binding on server then wanting all of the sorting and paging on the client. It seems the grid is making a "behind the scenes" call to serialize the datasource for use on the client. How can I hook in to that serialization and increase the max json size?

Hey Travis,
Can you also post the code for how you populate your Model.SearchResults and the Controller as well. Also, can you post the entire code for how you're constructing the grid (Razor)? The way I figured this is out is I accidentally saw that my Model for the grid is populating all of its properties when being created in the controller via its constructor. One of the properties is "Comments" and could get very long..... =) So, I eventually created a ViewModel and customized it to what I need to present/display on my grid.
Hope this helps, and if not, post your code and we can take a look.
Romel
Hello Travis,
The current Grid is still using an Ajax dataSource, so it is depending on the JavaScriptSerializer. I would suggest to check the following documentation page, which demonstrates how to increase the MaxJsonLength. You should also assure that there are no circular references in the model.
Regards,Dimiter Madjarov
Telerik

Yes I looked at that link as it was referred to in the original post and reply.
The ajax part of the datasource is so that sorting and filtering on done on the client while the data is bound through the view model in the grid constructor's razor code.
The exception occurs in the razor view where it seems it is serializing the view model data for use on the client. It looks to be happening "behind the scenes" I do not see anyway to hook in to this and provide a custom json serializer. If I add a read action to the datasource it won't have the form post data which contains the search criteria the grid's data is based on.

Hello Travis,
Please provide an isolated runnable example that demonstrates the issue (here or in a separate support ticket), so we could inspect it locally and pin-point the reason for the problem.
Regards,Dimiter Madjarov
Telerik

All of the documentation links for this post are 404 - I am still running into this issue.
Please change your internal code so that it follows this example when it is serialized
var json = Json(result, JsonRequestBehavior.AllowGet);
json.MaxJsonLength = Int32.MaxValue;
return json;
I cannot hook in to this through an MVC controller. You are serializing for the client as part of this code
.DataSource(dataSource => dataSource.Ajax().PageSize(10).ServerOperation(false))
The grid is server bound to the View Model in the cshtml
Hello Travis,
Indeed some of the documentation links have been moved. Here is the correct one for the article you are looking for.
Regards,Dimiter Madjarov
Telerik
Hello Maya,
The old invalid links have been replaced with working ones.