1

Using C# MVC ASP.NET:

hello, im trying to pass data from my controller to the view to display on a browser.

below is the data from my local SQL database that i want to return to show

MapController.cs

// Gets Traffic Speed Band data from database and returns as JSON object
        [HttpGet]
        public JsonResult GetSpeedBands()
        {
            //Creating List
            List<DataLibrary.Models.TrafficSpeedBandsModel> data1 = TrafficSpeedBandsProcessor.LoadTrafficSpeedBands();
            //List<DataLibrary.Models.BusStopsModel> data2 = BusStopsProcessor.LoadBusStops();

            //return list as Json
            return Json(data1, JsonRequestBehavior.AllowGet);
        }

View.cshtml

function ReadSpeedBands() {

            $.getJSON("/Map/GetSpeedBands",
                function (json) {                    
                    redlatlngs.push([1.3805895432850994, 103.74201730473243], [1.3800400299576012, 103.74120855605975]);
                    var polyline = L.polyline(redlatlngs, { color: 'red', opacity: 1, weight: 5 }).addTo(map);
                    ColorCodeSpeedBands(json);

                }
            );
}

the data that i wanna return is data1 but it is not showing on the map. i tested with another line of code which is data2 and it works. (basically, the red polyline shows up on the map when using data2 but not when using data1. I am able to writeline both data1 and data2 to console, so nothing is wrong with the data itself. that leaves the culprit to the return Json function)

so how come data1 is unable to work?

fyi, data1 contains a list of 58000 records, whereas data2 contains a list of 5000+ records

is it becuz the Json function can't return a large amount of data?

any help is appreciated!

Reza Jenabi
  • 3,884
  • 1
  • 29
  • 34
UVERtainment
  • 35
  • 1
  • 7
  • "that leaves the culprit to the return json function" - or whatever is actually using the JSON. I suggest you add more diagnostics to whatever is consuming the JSON so you can see what's happening on the client side. – Jon Skeet Jan 01 '20 at 09:14
  • It's likely that you have exceeded the max request length. Check this question for more info: https://stackoverflow.com/questions/3853767/maximum-request-length-exceeded – Sami Jan 01 '20 at 09:47
  • @Sami the question you shared is about request parameters not reply sizes. It could be but not in this case – Athanasios Kataras Jan 01 '20 at 10:23
  • i have played around abit, and the maximum records i can fetch is 9629 out of 58000 records. any more than that, my map would not show the data. im still not sure how to add diagnostics – UVERtainment Jan 01 '20 at 10:41
  • Try setting the max request length key in web.config to maximum int value. – Nagaraj Raveendran Jan 01 '20 at 13:15
  • still doesnt work. once i changed it to select 9630, the polylines wont show up – UVERtainment Jan 01 '20 at 14:14
  • Did you also set maxAllowedContentLength? – Sami Jan 02 '20 at 08:24
  • yes i set everything that is listed on the other post. but didnt work. in the end, i made a few loops that retrieves it bit by bit as opposed to returning the whole 58k records – UVERtainment Jan 02 '20 at 08:25

0 Answers0