Javascript Razor语法没有像我预期的那样工作

Javascript Razor语法没有像我预期的那样工作,javascript,razor,google-maps-api-3,Javascript,Razor,Google Maps Api 3,我有超过136个带有纬度和经度的位置,我正在尝试使用java脚本、razor和C#在一张好的地图上创建136个地图标记。问题是,razor中的JavaScript没有出现,我很好奇我是否做的每件事都正确 var mapMarker; @{ IEnumerable<UFA.Location.Core.Location> Location = UFALocation___Front.Helpers.QueryHelper.QueryHelper.getA

我有超过136个带有纬度和经度的位置,我正在尝试使用java脚本、razor和C#在一张好的地图上创建136个地图标记。问题是,razor中的JavaScript没有出现,我很好奇我是否做的每件事都正确

    var mapMarker;

    @{
        IEnumerable<UFA.Location.Core.Location> Location = UFALocation___Front.Helpers.QueryHelper.QueryHelper.getAllLocations();
        foreach(var loc in Location){
            <text>
                mapMarker = new google.maps.Marker({
                    position: new google.maps.LatLng(@loc.latitude, @loc.longitude),
                    map: map,
                    title: "Hello World!"
                });
            </text>
        }
    }
var映射标记;
@{
IEnumerable Location=UFALocation\uuuuuu Front.Helpers.QueryHelper.QueryHelper.getAllLocations();
foreach(位置中的var loc){
mapMarker=new google.maps.Marker({
位置:新的google.maps.LatLng(@loc.latitude,@loc.longitude),
地图:地图,
标题:“你好,世界!”
});
}
}
我基本上只是在所有位置循环,得到纬度和长度,问题是,标记不会出现,因为for each中的javascript片段不存在

全文如下:

function success(position) {
        var s = document.querySelector('#status');

        if (s.className == 'success') {
            // not sure why we're hitting this twice in FF, I think it's to do with a cached result coming back    
            return;
        }

        s.innerHTML = "found you!";
        s.className = 'label label-success';


        var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
        var directionsService = new google.maps.DirectionsService();
        var directionsDisplay = new google.maps.DirectionsRenderer();

        var map = new google.maps.Map(document.getElementById('map'), {
            zoom: 15,
            center: latlng,
            mapTypeControl: false,
            navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL },
            mapTypeId: google.maps.MapTypeId.ROADMAP
        });

        var marker = new google.maps.Marker({
            position: latlng,
            map: map,
            title: "You are here! (at least within a " + position.coords.accuracy + " meter radius)"
        });

        var mapMarker;

        @{
            IEnumerable<UFA.Location.Core.Location> Location = UFALocation___Front.Helpers.QueryHelper.QueryHelper.getAllLocations();
            foreach(var loc in Location){
                <text>
                    mapMarker = new google.maps.Marker({
                        position: new google.maps.LatLng(@loc.latitude, @loc.longitude),
                        map: map,
                        title: "Hello World!"
                    });
                </text>
            }
        }

        var SampleMarker = new google.maps.Marker({
            position: new google.maps.LatLng(51.379, -113.53),
            map: map,
            title: "Hello World!"
        }); 

        directionsDisplay.setMap(map);

        var request = {
            origin: latlng,
            destination: '304 304 26th ave sw calgary alberta',
            travelMode: google.maps.DirectionsTravelMode.DRIVING
        };

        directionsService.route(request, function (response, status) {
            if (status == google.maps.DirectionsStatus.OK) {
                directionsDisplay.setDirections(response);
            }
        });
    }

    function error(msg) {
        var s = document.querySelector('#status');
        s.innerHTML = typeof msg == 'string' ? msg : "failed";
        s.className = 'alert alert-error';

        // console.log(arguments);
    }

    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(success, error);
    } else {
        error('not supported');
    }
功能成功(位置){
var s=document.querySelector(“#status”);
如果(s.className=='success'){
//不确定为什么我们在FF中两次碰到这个,我认为这与缓存结果返回有关
返回;
}
s、 innerHTML=“找到你了!”;
s、 className='标签成功';
var latlng=新的google.maps.latlng(position.coords.latitude,position.coords.longitude);
var directionsService=new google.maps.directionsService();
var directionsDisplay=new google.maps.DirectionsRenderer();
var map=new google.maps.map(document.getElementById('map'){
缩放:15,
中心:拉特林,
mapTypeControl:false,
navigationControlOptions:{style:google.maps.NavigationControlStyle.SMALL},
mapTypeId:google.maps.mapTypeId.ROADMAP
});
var marker=new google.maps.marker({
位置:latlng,
地图:地图,
标题:“你在这里!(至少在“+位置.坐标.精度+”米半径内)
});
var标记;
@{
IEnumerable Location=UFALocation\uuuuuu Front.Helpers.QueryHelper.QueryHelper.getAllLocations();
foreach(位置中的var loc){
mapMarker=new google.maps.Marker({
位置:新的google.maps.LatLng(@loc.latitude,@loc.longitude),
地图:地图,
标题:“你好,世界!”
});
}
}
var SampleMarker=new google.maps.Marker({
位置:新google.maps.LatLng(51.379,-113.53),
地图:地图,
标题:“你好,世界!”
}); 
方向显示.setMap(地图);
var请求={
产地:拉丁美洲,
目的地:阿尔伯塔省卡尔加里西南第26大道304号,
travelMode:google.maps.Directions travelMode.DRIVING
};
路由(请求、功能(响应、状态){
if(status==google.maps.directionstatus.OK){
方向显示。设置方向(响应);
}
});
}
函数错误(msg){
var s=document.querySelector(“#status”);
s、 innerHTML=typeof msg=='string'?msg:“失败”;
s、 className='警报错误';
//log(参数);
}
if(导航器.地理位置){
navigator.geolocation.getCurrentPosition(成功,错误);
}否则{
错误('不支持');
}

您是否尝试过输出注释以查看循环中是否有任何东西在工作?它似乎从未进入
{}
内部,因为我在那里有断点,但在
中打印注释似乎只对咯咯笑有效,尝试将“循环”JavaScript放在一行,并使用@:而不是。例如@:mapMarker=新的google.maps.Marker(…);不显示,就像它从未进入代码块一样。您是否检查过getAllLocations()是否返回值?