【发布时间】:2013-04-10 03:21:24
【问题描述】:
我正在开发一个 asp.net mvc 门户来使用 localDB 管理 GPS 坐标。我的模型是:
public class GpsCoordinateViewModel
{
double Latitute { get; set; }
double Longitude { get; set; }
}
用于创建新 GpsCoordinate 的自动生成的广告相关视图是:
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>GpsCoordinateViewModel</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Latitude)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Latitude)
@Html.ValidationMessageFor(model => model.Latitude)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Longitude)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Longitude)
@Html.ValidationMessageFor(model => model.Longitude)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
问题是,当我插入纬度:41.213321 和经度:12.123432(例如)时,使用断点本地值是:纬度:41213321 经度:12123432。 由于位置的准确性,我需要使用 double,但是如何使用?
我也读过这个问题: How should I use EditorFor() in MVC for a currency/money type?
MVC3 - 3 decimal places on type double with leading zero
但解决方案对我不起作用。 有什么建议吗?
编辑: 我的网络配置是:
<system.web>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<!--
Enabling request validation in view pages would cause validation to occur
after the input has already been processed by the controller. By default
MVC performs request validation before a controller processes the input.
To change this behavior apply the ValidateInputAttribute to a
controller or action.
-->
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=number">
<controls>
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=number" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
<globalization culture="en-US" uiCulture="en-US" />
【问题讨论】:
-
你是说如果你输入带小数点的值,那么这些值会在你的控制器中作为整数接收?
-
嗨 von v. 是的,完全正确
-
这很有趣。即使没有这些数据注释格式,它也应该可以工作。我什至不认为文化信息与此有关,因为您根本没有分隔符!嗯……
-
@vonv。例如,法国(比利时)的文化信息(fr-BE),这里的有效数字是(123.456.789,00)。用于数字分组, , 是十进制符号。
-
这正是我的意思。有没有十进制符号为“空”的国家?
标签: asp.net html razor asp.net-mvc-4