UPDATED.
Following your suggestions, I implemented the function as shown below:
[HttpPost]
public ActionResult populate_place(string lati, string longi)
{
list_placesModels list_place = new list_placesModels();
list_place.Latitude = lati;
list_place.Longitude = longi;
return View();
}
However, after implementing this function, the new view is not displaying and it still shows the old view. The redirection to the new view is not happening for some reason.
////////////
I have integrated Google Maps geocoding feature into my Razor view in an ASP.NET MVC application to retrieve latitude and longitude data from locations. I want to pass this data to a controller function but nothing seems to be working. Below is a snippet of my code:
JavaScript code:
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker( {
map: map,
[0].geometry.location
});
// Trying to pass latitude and longitude values to list_places() function in UserController.
latitude = results[0].geometry.location.lat();
longitude = results[0].geometry.location.lng();
$.post("/User/list_places",
{
lati: latitude,
longi : longitude
});
Controller:
public ActionResult list_places(string usernameid, string lati, string longi) {
list_placesModels list_place = new list_placesModels();
list_place.Latitude = lati;
list_place.Longitude = longi;
return View(list_place);
}