JQuery Ajax with ASP.NET MVC Action: Passing arguments from JavaScript to POST

I have an ASP.NET MVC controller action with the following VB.NET signature:

<HttpPost()>
Public Function ClosestCities
   (ByVal position As MapCoordinate, ByVal citiesCount As UInteger) As JsonResult

Grade MapCordinate:

Public Class MapCoordinate
    Public Latitude As Double
    Public Longitude As Double
End Class

If I try to send an AJAX POST in jQuery to an action ClosestCities, what should my request look like?

When I use the following code for POST for this action, the VS debugger window, position.longitiudeand position.latitudeequal 0.0( 0D):

$.post("/geodata/closest-cities", { 
    position: {
        Longitude: mapPosition.lng(),
        Latitude: mapPosition.lat()
    },
    citiesCount: 5
}, function (cities) {
    debugger;
});
+3
source share
2 answers

, CType(), MapCoordinate . , .

MapCoordinate Latitude Longitude as, , , , .

? ?

+1

Source: https://habr.com/ru/post/1796196/


All Articles