.cshtml:
Код: Выделить всё
map.on('zoomend', function () {
var zoomLevel = map.getZoom();
// Enviar el nivel de zoom al backend
fetch('@Url.Page("/Map", "UpdateZoom")', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(zoomLevel)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
});
Код: Выделить всё
public IActionResult OnPostUpdateZoom([FromBody] string zoom)
{
ZoomLevel = JsonSerializer.Deserialize(zoom);
int valorCapturado = ZoomLevel;
return new JsonResult(new { success = true, receivedValue = valorCapturado });
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... e-back-end