ASP.NET MVC表单和双字段

前端之家收集整理的这篇文章主要介绍了ASP.NET MVC表单和双字段前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在开发一个asp.net mvc门户来使用localDB来管理GPS坐标.我的模型是:
public class GpsCoordinateviewmodel
{
    double Latitute { get; set; }
    double Longitude { get; set; }
}

自动生成的adn相关View创建一个新的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本地值为:纬度: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

解决方案对我不起作用.
有什么建议吗?

编辑:
我的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,PublicKeyToken=31BF3856AD364E35"
    userControlBaseType="System.Web.Mvc.ViewUserControl,PublicKeyToken=number">
  <controls>
    <add assembly="System.Web.Mvc,PublicKeyToken=number" namespace="System.Web.Mvc" tagPrefix="mvc" />
  </controls>
</pages>
<globalization culture="en-US" uiCulture="en-US" />

解决方法

可能是由cultureinfo,一些文化用途引起的,而不是.用于小数分隔符.尝试在web.config中设置以下内容,
<system.web>
    <globalization culture="en-US" uiCulture="en-US" />
</system.web>

希望这可以帮助

原文链接:https://www.f2er.com/aspnet/251206.html

猜你在找的asp.Net相关文章