我正在开发一个 asp.net mvc3 应用程序。
我正在尝试在局部视图中加载谷歌地图,但它不起作用:
我的局部视图_Map.cshtml
<style type="text/css">  
    #map_canvas 
    {
        position:absolute;
        top:40px;
        left:12px;
        width:576px;
        height: 450px;
    }
</style>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<div class="sTitle">Name</div>
<div id="map_canvas"></div>
<script type="text/javascript">
var map;
$(document).ready(function () {
    var map;
    var myOptions = {
        zoom: 8,
        center: new google.maps.LatLng(-34.397, 150.644),
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById('map_canvas'),
        myOptions);
    google.maps.event.addDomListener(window, 'load', initialize);
});
</script>
地图通过 AJAX 调用加载:
         $.ajax({
                type: 'GET',
                url: '@Url.Action("GetMapById", "Map")',
                data: { 'id': sId },
                success: function (html) {
                    $("#content").html(html);
                },
                complete: function () {
                },
                error: function () {
                    alert("There was an error opening the Map. Please try again or contact an administrator");
                }
            });
部分加载在名为 Content 的 div 中
在控制器中,我只返回部分视图
 return PartialView("_Map");
视图正在加载,但地图不可见。
我使用 Firebug 来跟踪问题,我得到了这个错误:
“google is not defined”
关于这个问题的任何想法?
非常感谢