I'm trying to do something like the following:
$.ajax({
url: "/Track/Search",
type: "POST",
data: {
startLatLng : { Latitude: firstClickLatLng.lat(), Longitude : firstClickLatLng.lng() },
endLatLng : { Latitude: secondClickLatLng.lat(), Longitude: secondClickLatLng.lng() }
},
dataType: "json",
success: function (msg) {
alert("Ah har!: " + msg);
}
});
With the following action signature:
[HttpPost]
public ActionResult Search(LatLng startLatLng, LatLng endLatLng)
And the class definition for LatLng as follows:
public class LatLng
{
public float Latitude { get; set; }
public float Longitude { get; set; }
}
But when I debug on the server the Longitude and Latitude fields are always null or set to zero. On the client-side this isn't the case though. I'm assuming I'm just doing something wrong with my data hash in the jQuery call.
Any ideas?
EDIT
Still no luck:
var myData = {
startLatLng: { Latitude: firstClickLatLng.lat(), Longitude: firstClickLatLng.lng() },
endLatLng: { Latitude: secondClickLatLng.lat(), Longitude: secondClickLatLng.lng() }
};
$j.ajax({
url: "/Track/Search",
type: "POST",
data: JSON.stringify(myData),
dataType: "json",
success: function (msg) {
alert("Ah har!: " + msg);
}
});
The call is made to the server, still no data though. Fields such as firstClickLatLng.lat() definitely have data.