ASP.NET MVC格式和双领域 [英] ASP.NET MVC Form and double fields
问题描述
我开发一个asp.net mvc的门户网站来管理使用的LocalDB GPS坐标。我的模型是:
I'm developing an asp.net mvc portal to manage GPS coordinates using localDB. My model is:
public class GpsCoordinateViewModel
{
double Latitute { get; set; }
double Longitude { get; set; }
}
自动生成的ADN相关视图中创建一个新的GpsCoordinate是:
the autogenerated adn related View to create a new GpsCoordinate is:
@{
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(EG),使用breakpoin当地的值是:纬度:41213321经度:12123432。
我需要的,因为定位的精度使用双,但如何?
the problem is that when I insert as Latitude: 41.213321 and Longitude: 12.123432 (eg), using breakpoin local values are: Latitude: 41213321 Longitude: 12123432. I need to use double because of location's accuracy, but how?
我也看了这个问题:
<一href=\"http://stackoverflow.com/questions/5080451/how-should-i-use-editorfor-in-mvc-for-a-currency-money-type\">How我应该使用MVC EditorFor()的货币/货币类型?
<一个href=\"http://stackoverflow.com/questions/7375729/mvc3-3-decimal-places-on-type-double-with-leading-zero\">MVC3 - 对3型小数位的双领先的零
但方案并没有为我工作。
任何建议?
but the solutions didn't work for me. Any suggestion?
编辑:
我的webconfig是:
My webconfig is:
<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" />
推荐答案
可能受到的CultureInfo引起的,有些文化使用,
而不是。
的小数点分隔符。尝试设置以下在web.config中,
Might be caused by cultureinfo, some culture use ,
instead of .
for decimal separator. try setting the following in web.config,
<system.web>
<globalization culture="en-US" uiCulture="en-US" />
</system.web>
希望这有助于
这篇关于ASP.NET MVC格式和双领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!