-3

i am working with MVC4. Receiving 500 (Internal Server Error) error while requesting for bulk amount of data. i think it is because of heavy amount of data. how to fix it ??? Error description is :

'Error during serialization or de-serialization using JSON JavaScriptSerializer. The length of the string exceeds the value set on the MaxJasonLength property.'

i have tried this in web.config:

<add key="aspnet:MaxJsonDeserializerMembers" value="1500000000000" />

but still no difference!

pnuts
  • 58,317
  • 11
  • 87
  • 139
Baqer Naqvi
  • 6,011
  • 3
  • 50
  • 68

2 Answers2

1

You are correct, there are a few places that you need to update the value to override the default maximum lengths. What you have posted as your attempt is not the correct place however.

First, update your web.config with the following block

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

If you are still having issues (as I think this setting is not honored in a controller for some reason on MVC4), you can try the following when you are actually serializing the data.

var serializer = new JavaScriptSerializer();
serializer.MaxJsonLength = Int32.MaxValue;

var jsonData = new { key = Records };
var result = new ContentResult{
    Content = serializer.Serialize(jsonData),
    ContentType = "application/json"
};
return result;
Tommy
  • 39,592
  • 10
  • 90
  • 121
-1

In MVC 4 you have the async controller options. I suppose you are having a grid with huge sets of data. This kind of scenario used to work well in classic ASP. There developers will periodically flush the response after certain number of rows are generated. But in ASP.Net webforms and ASP.Net MVC you have to handle them differently. Async controller will give some good performance here. I referred msdn article http://msdn.microsoft.com/en-us/library/ee728598(v=vs.100).aspx

    public void IndexAsync(string input)
    {
        List<Sample> test = new List<Sample>();
        AsyncManager.OutstandingOperations.Increment();
        //You can replace this GetHashCode with different webservice call or some other delaying task
        for (int i = 0; i < 100000; i++)
        {
            test.Add(new Sample {SampleID=i,Name="Meow" });
        }
        AsyncManager.Parameters["inp"] = test;
        AsyncManager.OutstandingOperations.Decrement();
    }
    public  ActionResult IndexCompleted(IList<Sample> inp)
    {
       return View(inp);
    }
Thanigainathan
  • 1,505
  • 14
  • 25