ASP.NET MVC4 Razor的Javascript版本。谷歌地图没有加载
我对ASP.NET MVC4 Razor的Javascript版本。谷歌地图没有加载,javascript,jquery,asp.net-mvc-4,razor,google-maps-api-3,Javascript,Jquery,Asp.net Mvc 4,Razor,Google Maps Api 3,我对setMarkers()函数有一些问题,我的地图根本不显示。我认为我在setMarkers函数中的Razor语法中犯了一些错误。你能提出一个解决方案吗? 由于我不是这项技术的专家,在Javascript函数中混合使用Razor是正常的还是应该遵循另一种更好的做法,即将脚本函数移动到@部分的功能范围内? 提前谢谢 我的MarkerModel: public class MarkerModel { public string Description { get; set;
setMarkers()
函数有一些问题,我的地图根本不显示。我认为我在setMarkers函数中的Razor语法中犯了一些错误。你能提出一个解决方案吗?
由于我不是这项技术的专家,在Javascript函数中混合使用Razor是正常的还是应该遵循另一种更好的做法,即将脚本函数移动到@部分的功能范围内?
提前谢谢
我的MarkerModel:
public class MarkerModel
{
public string Description { get; set; }
public double latitude { get; set; }
public double longitude { get; set; }
public int zIndex { get; set; }
}
我的看法是:
@model IEnumerable<DAssistant.Web.Models.MarkerModel>
<style type="text/css">
#map-canvas
{
height: 500px;
}
</style>
@{
ViewBag.Title = "Map";
}
@section featured {
<div id="map-canvas"></div>
}
<script type="text/javascript" src="http://www.google.com/jsapi?autoload={'modules':[{name:'maps',version:3,other_params:''}]}"></script>
<script type="text/javascript">
function init() {
var mapDiv = document.getElementById('map-canvas');
var mapOptions = {
center: new google.maps.LatLng(-33.890542, 151.274856),
zoom: 8,
mapTypeControl: true,
zoomControl: true,
scaleControl: true,
streetViewControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(mapDiv, mapOptions);
setMarkers(map);
}
function setMarkers(map) {
@foreach (var item in Model)
{
<text>
var myLatLng = new google.maps.LatLng(@item.latitude, @item.longitude);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: @item.Description,
zIndex: @item.zIndex
});
</text>
}
}
google.maps.event.addDomListener(window, 'load', init);
</script>
@model IEnumerable
#地图画布
{
高度:500px;
}
@{
ViewBag.Title=“地图”;
}
@特色栏目{
}
函数init(){
var mapDiv=document.getElementById('map-canvas');
变量映射选项={
中心:新google.maps.LatLng(-33.890542151.274856),
缩放:8,
mapTypeControl:true,
动物控制:对,
scaleControl:对,
街景控制:对,
mapTypeId:google.maps.mapTypeId.ROADMAP
}
var map=new google.maps.map(mapDiv,maptoptions);
设置标记(地图);
}
函数设置标记(map){
@foreach(模型中的var项目)
{
var myLatLng=new google.maps.LatLng(@item.latitude,@item.longitude);
var marker=new google.maps.marker({
职位:myLatLng,
地图:地图,
标题:@item.Description,
zIndex:@item.zIndex
});
}
}
google.maps.event.addDomListener(窗口'load',init);
更改此选项:
title: @item.Description
致:
例如,描述为“某些字符串”,则标题为:
title: some string
这是无效的javascript。,我想这应该在你的身体里,如果我错了请纠正我浏览器开发工具中的任何错误?这辆车看起来不对劲。它一遍又一遍地定义相同的变量。Chrome javascript控制台中没有错误,这是字符串问题:)
title: some string