This is a migrated thread and some comments may be shown as answers.

3,500 rows...maxJsonLength hit!

4 Answers 249 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Carmine
Top achievements
Rank 1
Carmine asked on 04 Aug 2011, 04:50 AM
Have a rather simple grid with a dozen or so columns, three of which have server and client templates (since I'm sending down all data at once...don't want to have more requests for sorting, paging, etc.).

Above 3,500 rows or so I get the dreaded:

Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.


So, short of modifying the core Telerik code, is there any way I can use this grid? I can get unlimited rows using SlickGrid and such, but I would dearly love Telerik to work. Any thoughts?

Thanks,
Cimeran

4 Answers, 1 is accepted

Sort by
0
Steve
Top achievements
Rank 1
answered on 04 Aug 2011, 07:00 AM

You can configure the max length for json requests in your web.config file:


<configuration> 
   
<system.web.extensions> 
       
<scripting> 
           
<webServices> 
               
<jsonSerialization maxJsonLength="...."> 
               
</jsonSerialization> 
           
</webServices> 
       
</scripting> 
   
</system.web.extensions> 
</configuration> 

The default value for maxJsonLength is 102400. For more details, see this MSDN page: http://msdn.microsoft.com/en-us/library/bb763183.aspx

if, after implementing the above addition into your web.config, you get an “Unrecognized configuration section system.web.extensions.” error then try adding this to your web.config in the <ConfigSections> section:

        <sectionGroup name="system.web.extensions" type="System.Web.Extensions"> 
             
<sectionGroup name="scripting" type="System.Web.Extensions"> 
                   
<sectionGroup name="webServices" type="System.Web.Extensions"> 
                         
<section name="jsonSerialization" type="System.Web.Extensions"/> 
                   
</sectionGroup> 
             
</sectionGroup> 
       
</sectionGroup> 

Source: http://stackoverflow.com/questions/1151987/unlimited-for-maxjsonlength

0
Carmine
Top achievements
Rank 1
answered on 04 Aug 2011, 01:40 PM
I've made those changes in web.config, but in MVC applications that setting is ignored. I could roll a custom ActionResult, but to use it I would have to modify the Telerik core files. Any other options? I can't seem to find any.

Carmine
0
Iakov
Top achievements
Rank 1
answered on 25 Nov 2011, 10:00 AM
As a solution, I have modified Telerik.Web.Mvc.UI.GridActionResultFactory class to the following:

class GridActionResultFactory : IGridActionResultFactory
{
    public ActionResult Create(object model)
    {
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        serializer.MaxJsonLength = Int32.MaxValue;
        string serializedData = serializer.Serialize(model);
 
        return new ContentResult()
        {
            Content = serializedData,
            ContentType = "application/json"
        };
 
    }
}


After that,  in my project I have replaced the default Telerik.Web.Mvc assembly with the customized one.
0
David
Top achievements
Rank 1
answered on 06 Aug 2012, 08:06 AM
Look at my post: http://www.telerik.com/community/forums/aspnet-mvc/grid/multiple-data-rows-result-problem.aspx there is a better solution of this problem...
Tags
Grid
Asked by
Carmine
Top achievements
Rank 1
Answers by
Steve
Top achievements
Rank 1
Carmine
Top achievements
Rank 1
Iakov
Top achievements
Rank 1
David
Top achievements
Rank 1
Share this question
or