Every time I attempt to pass data from the view to the controller, I keep receiving an "alert request failed" message.
I am uncertain of the datatype for leafletLats and leafletLngs, but they are both arrays derived from coord which is of type LatLng[].
Could someone help me identify what may be causing the Post method to not go through? Is there an issue in the controller?
In the View:
routeControl.on('routeselected', function (e) {
var coord = e.route.coordinates;
var name = e.route.name;
var leafletLats = coord.map(function(point) {
return [point.lat];
});
var leafletLngs = coord.map(function(point) {
return [point.lng];
});
alert('Array size = ' + coord.length + '\nCoordinates: \n' + leafletLats);
alert('Array size = ' + coord.length + '\nCoordinates: \n' + leafletLngs);
$.ajax({
type: 'Post',
url: '/Map/GetRouteCoordinates',
data: JSON.stringify(leafletLats),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
alert(`Request passed!`);
console.log(data);
},
error: function (jqXHR, textStatus, errorThrown) {
alert(`Request failed!`);
}
});
In the controller:
[HttpPost]
public ActionResult GetRouteCoordinates(MyModel test)
{
//do something with the result
Debug.WriteLine("data passed back");
return View();
}
public class MyModel
{
public List<MyModel_Value> latList { get; set; }
}
public class MyModel_Value
{
public double lat { get; set; }
}