Asp.net mvc Asp.Net:将字符串转换为长字符串

Asp.net mvc Asp.Net:将字符串转换为长字符串,asp.net-mvc,razor,Asp.net Mvc,Razor,我正在尝试保存google.maps.Geocoder()获取的地理位置数据。 从javascript中,我将这些值设置为html中的一个(实际上)隐藏元素(工作正常): 我想从那里将值传递到控制器: @Html.TextBoxFor(model => model.Longitude, new { id = "longitude", type = "number" }) @Html.TextBoxFor(model => model.Latitude, new { id = "lat

我正在尝试保存google.maps.Geocoder()获取的地理位置数据。 从javascript中,我将这些值设置为html中的一个(实际上)隐藏元素(工作正常):

我想从那里将值传递到控制器:

@Html.TextBoxFor(model => model.Longitude, new { id = "longitude", type = "number" })
@Html.TextBoxFor(model => model.Latitude, new { id = "latitude", type = "number"})
根据小数分隔符的不同,我会得到一个验证错误,或者经度和纬度的值没有设置到模型中。这两个属性都是long类型

为什么Asp.Net不能自动解析这些值? 我对Asp.Net非常陌生,但我知道我还可以:

  • 编写自己的html助手
  • 将视图模型传递到我的控制器或
  • 持久化字符串值
我应该选择哪种方式


谢谢,Rico

您会遇到错误,因为
long
存储的是大的64位整数值(实际上是
Int64
幕后),而不是浮点值


如果您想让代码使用浮点值,您需要使用类似于
float
double

Ahhh。。。有时我看不到树木的树木:-)当然,我需要使用双,而不是。。。为我的愚蠢道歉:-)
@Html.TextBoxFor(model => model.Longitude, new { id = "longitude", type = "number" })
@Html.TextBoxFor(model => model.Latitude, new { id = "latitude", type = "number"})