无效的Double.ToString()导致生成javascript的razor代码

Joh*_*kke 6 javascript c# asp.net-mvc google-maps razor

我使用以下剃刀代码生成一些javascript以在Google地图上生成标记.

@foreach(Point point in Model.Points.Take(3))
{
    String longitude = point.Longitude.ToString(CultureInfo.InvariantCulture);
    String latitude = point.Latitude.ToString(CultureInfo.InvariantCulture);
    <text>
        var location = new google.maps.LatLng(@(longitude), @(latitude));
        bounds.extend(location);
        var marker = new google.maps.Marker({
            position: location,
            map: map
        });
    </text>
}
Run Code Online (Sandbox Code Playgroud)

在开发中,这正确地变为:

var location = new google.maps.LatLng(52.2124273, 5.9545532);
bounds.extend(location);
var marker = new google.maps.Marker({
    position: location,
    map: map
});
Run Code Online (Sandbox Code Playgroud)

但是,在我们的生产服务器上,它变为:

var location = new google.maps.LatLng(522124273000, 59545532000);
bounds.extend(location);
var marker = new google.maps.Marker({
    position: location,
    map: map
});
Run Code Online (Sandbox Code Playgroud)

这只是一个灰色的谷歌地图.是什么导致了这种奇怪的ToString行为?

编辑

Point类是一个自定义类,而不是来自库.以下是相关部分:

public class Point
{
    private Double latitude;
    private Double longitude;

    public Double Latitude
    {
        get
        {
            return latitude;
        }
    }

    public Double Longitude
    {
        get
        {
            return longitude;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Joh*_*kke 1

JK 和 AlexC 是对的,请参阅他们对我的问题的评论。来自外部 API 的数据有误。将全球文化设置为 en-US 解决了这个问题。

我只不明白一件事:我正在使用一个使用 JSON.net 的库,文档中到处都说解析是使用 InvariantCulture 完成的。所以我认为全球文化不会产生影响。