We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Chart Control does not understand ContentResult and JSONResult fails because of length restriction

Hi Team,

If my Controller method that returns JSON to the chart is below, it is working (as long as number of records I request is 5000). When the number of records exceeds this value it causes a Internal Server Error inspite of me having a maximum possible value for    <jsonSerialization maxJsonLength="2147483644"/> in web.config

       [HttpPost]
        public JsonResult chart(int intNumberOfRecords)
        {
            string allText = GetData(intNumberOfRecords);
            return Json(allText);
        }

Hence I am trying to change the method as below

        [HttpPost]
        public ContentResult chart(int intNumberOfRecords)
        {
            //string allText = System.IO.File.ReadAllText(Server.MapPath("~/App_Data/points.json"));
            string allText = GetData(intNumberOfRecords);
            return new ContentResult() { Content=allText,ContentEncoding="application/json"};
        }

Now the chart control does not read the data.

Please help...

Thanks,

Deepak

1 Reply

AT Anandaraj T Syncfusion Team October 6, 2016 08:41 AM UTC

Hi Deepak, 

Thanks for using Syncfusion products. 

We have prepared a simple sample to bind chart with data from JSONResult and ContentResult action methods. The sample can be downloaded from the following link 

Query #1: When the number of records exceeds this value (5000) it causes a Internal Server Error inspite of me having a maximum possible value for    <jsonSerialization maxJsonLength="2147483644"/> in web.config 

We can avoid this limitation by setting the MaxJsonLength value programmatically. Also, MVC application does not consider the jsonSerialization attribute in web.config file if we use Json method to return JsonResult

Please refer the following code snippet to achieve this 

[C#] 
 
        [HttpPost] 
        public JsonResult chart(int intNumberOfRecords) 
        { 
            string allText = GetData(intNumberOfRecords); 
            //Set MaxJsonLength programatically to avoid restriction 
            return new JsonResult() { MaxJsonLength = Int32.MaxValue, Data = allText }; 
        } 

Query #2: Chart control does not understand ContentResult 
 
We have analyzed your code and found that ContentEncoding property was used instead of ContentType. After making this change, the application works fine. 
 
Please refer the modified code snippet in following table 
 
[C#] 
 
        [HttpPost] 
        public ContentResult chartdata(int intNumberOfRecords) 
        {             
            string allText = GetData(intNumberOfRecords); 
            return new ContentResult() { Content = allText, ContentType = "application/json" }; 
        } 

Please let us know if you have any concern. 

Regards, 
Anand 


Loader.
Live Chat Icon For mobile
Up arrow icon