简体   繁体   中英

Not able to pass more than 1000 records to kendo gridview

I am using Kendo Gridview to display some records. These records are in Json when retrieved from the database and stored in a list of the same class. I have no problem when the list is of count 1000, but any number above 1000 triggers an exception : " during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property. " 。字符串的长度超过了在maxJsonLength属性上设置的值。 ”

I have tried changing the maxJsonLength value in web.config and in appsettings as recommended in some of the solutions I found on stack overflow. But none of them work. This is my view:

@(Html.Kendo().Grid(Model)

.Name("grid")
.Scrollable()
.Filterable()
.Columns(columns =>
    {
        //Columns added here
    })
.Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
.Pageable(pageable => pageable
.Refresh(false)
.PageSizes(true)
.ButtonCount(3))
.DataSource(dataSource => dataSource
    .Ajax()
    .ServerOperation(false)
    .Model(model =>
        {
            model.Id(p => p.Id);
            model.Field(p => p.Id).Editable(false);

        })
    .Read(read => read.Action("Action", "Controller"))
    .PageSize(50)
    )
.Events(e => e.DataBound("selectDefault"))

I came to realize that the Json Lists that I was passing to the view had too many complex data types(ie class objects and enums) and that was the reason none of the solutions worked. So I referred to a solution described in this link and created an intermediate view model. In this model I added all the necessary attributes that I wanted and passed it to view. It works really fine now

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM