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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Thread ID:





126277 Oct 5,2016 11:43 AM UTC Oct 6,2016 08:41 AM UTC ASP.NET MVC 1
Tags: Chart
Asked On October 5, 2016 11:43 AM UTC

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

        public JsonResult chart(int intNumberOfRecords)
            string allText = GetData(intNumberOfRecords);
            return Json(allText);

Hence I am trying to change the method as below

        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...



Anandaraj T [Syncfusion]
Replied On 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 

        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 
        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. 



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon