gpt4 book ai didi

ASP.NET MVC 表单和双字段

转载 作者:太空狗 更新时间:2023-10-29 13:29:47 25 4
gpt4 key购买 nike

我正在开发一个 asp.net mvc 门户来使用 localDB 管理 GPS 坐标。我的模型是:

public class GpsCoordinateViewModel
{
double Latitute { get; set; }
double Longitude { get; set; }
}

创建新 GpsCoordinate 的自动生成的 adn 相关 View 是:

@{
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" />

最佳答案

可能是cultureinfo引起的,一些culture使用,代替.作为小数点分隔符。尝试在 web.config 中设置以下内容,

<system.web>
<globalization culture="en-US" uiCulture="en-US" />
</system.web>

希望对你有帮助

关于ASP.NET MVC 表单和双字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16058760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com