我正在開發一個asp.net mvc門戶來管理使用localDB的GPS座標。我的模型是:ASP.NET MVC窗體和雙字段
public class GpsCoordinateViewModel
{
double Latitute { get; set; }
double Longitude { get; set; }
}
自動生成的ADN相關視圖中創建一個新的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(例如),使用breakpoin本地值是:Latitude:41213321 Longitude:12123432. 由於位置的準確性,我需要使用double,但是如何?
我也看了這個問題: How should I use EditorFor() in MVC for a currency/money type?
MVC3 - 3 decimal places on type double with leading zero
但解決方案並沒有爲我工作。 有什麼建議嗎?
編輯: 我的webconfig是:
<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" />
你是說如果你輸入一個小數點的數值,那麼這些數值就會作爲整數在你的控制器中被接收到? –
Hi von訴 是的,正好是 – antedesk
這很有趣。即使沒有這些數據註釋格式,它也應該可以工作。我甚至不認爲文化信息與此有關,因爲你根本沒有得到分隔符!嗯... –