我正在从我的控制器返回一个显示网格的模型。工作正常。我还需要使用相同的数据在谷歌地图上生成点。我在需要替换的原型中设置了以下代码:
var locationsAll = [
["Pretty", 40.1508, -83.21],
["Little", 40.1308, -83.11],
["Smug", 40.001, -83.01],
["Troublemaker", 40.109, -83.291],
["Smallest", 40.08, -83.20]
];
PlotpointsonMap(locationsAll);
到现在为止还挺好。这有效,所以我将其转换为 javascript,如下所示:
@{
var locations = "[";
foreach (var gmap in Model.MapPoints )
{
locations += "['" + gmap.EventStringData + "'," + gmap.Latitude + "," + gmap.Longitude + "],";
}
locations = locations.TrimEnd(',') + "]";
}
var myLocations = @locations;
PlotpointsonMap(myLocations);
但是,这一半有效。当我查看生成的源代码时,我的 javascript 块中出现以下代码:
var myLocations = [["update",40.080398,-83.139141]
我需要它像这样渲染:
var myLocations = [["update",40.080398,-83.139141]
任何关于如何实现这一点的想法都非常感谢。我试过:
var myLocations = @Server.HtmlDecode(locations);
它给了我同样的结果:(