0
votes

I'have project in Visual Studio in Framework 4.5.

It is a ASP.NET MVC 4 WebApllication. I'm using JSON to get a lot of data. But when i execute it, it gives me that error: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.

So, i want to modify max json length with this code:

 protected override JsonResult Json(object data, string contentType, System.Text.Encoding contentEncoding, JsonRequestBehavior behavior)
    {
        return new JsonResult()
        {
            Data = data,
            ContentType = contentType,
            ContentEncoding = contentEncoding,
            JsonRequestBehavior = behavior,
            MaxJsonLength = Int32.MaxValue 
        };
    }

But i can't, because I get an error in line **MaxJsonLength = Int32.MaxValue **

Error is: System.Web.Mvc.JsonResult' does not contain a definition for 'MaxJsonLength

I have these references in class of controller:

  • using System;
  • using System.Collections.Generic;
  • using System.Linq;
  • using System.Web;
  • using System.Web.Mvc;
  • using WebserviceIPAD.Areas.Api.Models;
  • using System.Web.Script.Serialization;

But still getting an error: System.Web.Mvc.JsonResult' does not contain a definition for 'MaxJsonLength

Any one knows if I have to import more references?

Thanks.

enter image description here

2
I checked MSDN, there is a property as MaxJsonLength. When you write the MaxJsonLength, do you see it in intellisense? - Uğur Aldanmaz
I just updated my question, I see MaxJsonLength as it is in image. - HaOx

2 Answers

1
votes

Can I set an unlimited length for maxJsonLength in web.config?

It can be set in the config:

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

I just found a solution. I have created new project, every classes and configuration one more time. And know without any problem I can use MaxJsonLength.

Thanks for every one for suggestions.