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!