0

I want to display content into InfoWindow from controller action (return partial view). When i click Mraker it shows 'Undefined' into infowindow.

How to render partial view into google map InfoWindow?

    function AjaxDisplayString() {
        var addressData;
        var testData;
        $.ajax({
            type: "GET",
            url: '/Account/Tooltip',
           dataType: "HTML",
            contentType: 'application/json',
            traditional: true,
            data: addressData,
            success: function (result) {
                debugger;
                return result                   
            },
            error: function (arg) {
                alert("Error");
            }

        });

    }

    var infowindow = new google.maps.InfoWindow({
        content: "<div>"+ AjaxDisplayString() + "</div>"

    });


    google.maps.event.addListener(marker, 'click', function () {
        infowindow.open(map, marker);
    });

1 Answers1

0

AjaxDisplayString is ajax call hence result arrives little late but you tend to open infowindow immediately. Modify the calls as below and it shall work.

 var infowindow = new google.maps.InfoWindow({
        content: "";
    });


function AjaxDisplayString() {
        var addressData;
        var testData;
        $.ajax({
            type: "GET",
            url: '/Account/Tooltip',
           dataType: "HTML",
            contentType: 'application/json',
            traditional: true,
            data: addressData,
            success: function (result) {
                debugger;
                infowindow.setContent("<div>"+ result + "</div>");  
                infowindow.open(map, marker);               
            },
            error: function (arg) {
                alert("Error");
            }

        });

    }

    google.maps.event.addListener(marker, 'click', function () {
        AjaxDisplayString(map, marker)
    });
jsjunkie
  • 559
  • 3
  • 7