this is my javascript function:
function addMarker(x, y, meas_type, meas_status, meas_key) {
var location = new google.maps.LatLng(x, y);
var contentString = '<h3 >' + meas_type + '</h3>' + '<p>Status: ' + '<span style="color: red">' + meas_status + '</span>' + '</p>' + '<input type="button" class="btn btn-default" value="Details" onclick="window.location.href=\'@Url.Action("Index", "Home", new { param = meas_key})\';" />' + ' ';
var marker = new google.maps.Marker({
position: location,
map: map,
});
var infowindow = new google.maps.InfoWindow({
content: contentString
});
google.maps.event.addListener(marker, 'click', function () {
infowindow.open(map, marker);
});
}
Now in the contentString variable, I want to pass to the Index method meas_key as a parameter! How can I do it? It's not working like this.
This one works fine but I need to send meas_key as a parameter:
var contentString = '<h3 >' + meas_type + '</h3>' + '<p>Status: ' + '<span style="color: red">' + meas_status + '</span>' + '</p>' + '<input type="button" class="btn btn-default" value="Details" onclick="window.location.href=\'@Url.Action("Index", "Home")\';" />' + ' ';
Problem here is that @Url.Action
is done on server side, and of course there is no way to pass a javascript variable there. So you might need to do something like this:
var url = '@Url.Action("Index", "Home")' + '?param=' + meas_type;
var contentString =
'<h3 >' + meas_type + '</h3>'
+ '<p>Status: ' + '<span style="color: red">' + meas_status + '</span>' + '</p>'
+ '<input type="button" class="btn btn-default" value="Details" onclick="window.location.href=' + url + '" />'
+ ' ';
And you might want to consider templating of some kind to make this HTML construction a bit more readable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.