Вы можете использовать AJAX:
$.ajax({
url: '@Url.Action("AutoLocate")',
type: 'GET',
data: postData,
success: function(result) {
// process the results from the controller
}
});
, где postData = { latitude: latitude, longtitude: longitude };
.
Или, если у вас есть actionlink:
@Html.ActionLink("foo bar", "AutoLocate", null, null, new { id = "locateLink" })
, вы можете AJAXify эту ссылку какэто:
$(function() {
$('#locateLink').click(function() {
var url = this.href;
navigator.geolocation.getCurrentPosition(function(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var postData = { latitude: latitude, longtitude: longitude };
$.ajax({
url: url,
type: 'GET',
data: postData,
success: function(result) {
// process the results from the controller action
}
});
});
// cancel the default redirect from the link by returning false
return false;
});
});