Hello everyone,

I am very new to asp.net and asp.net mvc as well. I am stuck with the following problem please help. I have the following javascript

<script type="text/javascript">
        var allMarks = [];
        google.load("maps", "2");
        var geocoder;
       var lat;
        function initialize() {
            var map = new google.maps.Map2(document.getElementById("map"));
            map.setCenter(new google.maps.LatLng(37.4419, -122.1419), 10);
            map.setUIToDefault();
            GEvent.addListener(map, "click", function (overlay, latlng) {
                if (latlng) {
                    var marker = new GMarker(latlng);
                    allMarks.push(latlng);
                    map.addOverlay(marker);
                    marker.openInfoWindow(latlng.toString());
                    lat = latlng.toString();
              }
            });
           
            geocoder = new google.maps.Geocoder();
        }
        google.setOnLoadCallback(initialize);
 
    </script>

Now how can i pass lat variable value in javascript to my asp.net mvc actionresult method in the controller. The method is like

public ActionResult GetValues(string Latitude)
{
     //Get the value from javascript, process the value here
}

Thank you

Edited 5 Years Ago by manugm_1987: n/a

I've used hidden fields on the page to do this. Others may have a better way but this has worked OK for me before. Include a label as a hidden field on the page and write the variable into it using javascript.
Your .Net code can then read from the label, obtaining the variable.

I've used hidden fields on the page to do this. Others may have a better way but this has worked OK for me before. Include a label as a hidden field on the page and write the variable into it using javascript.
Your .Net code can then read from the label, obtaining the variable.

Thanks for the reply. I am using asp.net MVC will this hidden fields work for MVC as well.

The best solution is use Json string and pass that string to your action result method.

This article has been dead for over six months. Start a new discussion instead.