Click here to Skip to main content
15,885,855 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using MVC2.0 and telerik control for UI data binding.
My action in controller is
public ActionResult SearchFilter(RequestModel filterModel)
{
var retList = new List<iadjustment>();
var retList = (List<iadjustment>)GetAllSearchRecords(filter);
return View(new GridModel(retList));
}

in above code Grid model expecting List<t>. it works fine. When data size large, getting below error.
System.InvalidOperationException: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property


Can anyone help me how to resolve this?

What I have tried:

I tried with serializer
var serializer = new JavaScriptSerializer();
serializer.MaxJsonLength = Int32.MaxValue;
return View(new GridModel(serializer.Serialize(retList)));

But Grid model expecting List<t>.
Posted
Updated 31-Jan-17 9:53am

1 solution

Your question is a bit confusing. Which code are you really using and which fails with the large data set?

Sending a List<t> to the View doesn't serialize anything to JSON. It's just an object passed to the Razor view engine when the Razor code is executed to generate the HTML for the returned page.

You'd use JSON to return an object back to the client, normally for a data request, not a page request.

I'll tell you that the default allowable length of a JSON return string is 102,400 characters. You can change that in a couple of ways. The easiest (and global) way to do that for your entire application is to add a setting to your web.config file:
XML
<configuration> 
   <system.web.extensions>
       <scripting>
           <webServices>
               <jsonSerialization maxJsonLength="2147483644" />
           </webServices>
       </scripting>
   </system.web.extensions>
</configuration>

The other method is to just set the MaxJsonLength property of the serializer you created, which you say you've already done.

Now, if you're still getting that error message, it's because your generated JSON string is greater than MaxJsonLength. In your example, that would be a JSON string greater than 2 GIGABYTES in size. Sending that much data back to the client is a horrible idea.
 
Share this answer
 
Comments
Raj kumar.C 1-Feb-17 2:57am    
when i send serialize json object, data is not binding. Beacuase it is expecting class object not Json string.
Dave Kreskowiak 1-Feb-17 8:49am    
Yeah, because the Razor engine doesn't use JSON. It uses an actual object.

Seriously, pickup a book on MVC and work through it. This is a very basic MVC concept.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900