C# MVC4文化冲突

C# MVC4文化冲突,c#,jquery,asp.net-mvc,unobtrusive-javascript,C#,Jquery,Asp.net Mvc,Unobtrusive Javascript,我正在使用MVC4和实体框架开发一个intranet web应用程序。从开发开始,我就有一个无法解决的问题。为了说明我所说的,这里有一个例子: 我可以通过“创建视图”添加一个人。在这种观点下,我必须精确地计算一个十进制数字,它代表了一个人的房子和工作地点之间的距离。在这个阶段,一切都很好。但是,当我想要编辑一个人并保存更改时,该数字不被接受为十进制数字 我读到了我的问题,并尝试在web.config中添加一个标记,精确地定义我想要使用的文化(确切地说,是法国文化) 这是我的“编辑视图”: 如果不

我正在使用MVC4和实体框架开发一个intranet web应用程序。从开发开始,我就有一个无法解决的问题。为了说明我所说的,这里有一个例子:

我可以通过“创建视图”添加一个人。在这种观点下,我必须精确地计算一个十进制数字,它代表了一个人的房子和工作地点之间的距离。在这个阶段,一切都很好。但是,当我想要编辑一个人并保存更改时,该数字不被接受为十进制数字

我读到了我的问题,并尝试在web.config中添加一个标记,精确地定义我想要使用的文化(确切地说,是法国文化)

这是我的“编辑视图”:


如果不引人注目的javascript验证结果与服务器端验证结果不同,则您的问题可能与


我们遇到了类似的问题,此线程帮助解决了该问题。

您会遇到什么样的错误?或者它只是在小数点处被截断,或者只是转换为int?低调的Javascript验证结果与服务器端的验证结果是否不同?我们在十进制分隔符方面也有类似的问题,但只有服务器端验证按预期工作。您也可以发布操作方法的代码吗?这似乎是客户端错误。事实上,我不能修改我的人而不替换这个“,”或只是删除它。我的文本框旁边会出现一条红色错误消息。这是我的行动方法。@Traffy那么您的问题可能与感谢您的帮助有关;)
@model BuSIMaterial.Models.Person
@{
    ViewBag.Title = "Edit";
}
<h2>
    Edit</h2>
<script src="@Url.Content("~/Scripts/jQueryFixes.js")" type = "text/javascript"></script>
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Person</legend>
        @Html.HiddenFor(model => model.Id_Person)
        <div class="editor-label">
            First name :
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.FirstName, new { maxlength = 50 })
            @Html.ValidationMessageFor(model => model.FirstName)
        </div>
        <div class="editor-label">
            Last name :
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.LastName, new { maxlength = 50 })
            @Html.ValidationMessageFor(model => model.LastName)
        </div>
        <div class="editor-label">
            National number :
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.NumNat, new { maxlength = 11 })
            @Html.ValidationMessageFor(model => model.NumNat)
        </div>
        <div class="editor-label">
            Start date :
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.StartDate, new { @class = "datepicker" })
            @Html.ValidationMessageFor(model => model.StartDate)
        </div>
        <div class="editor-label">
            End date :
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.EndDate, new { @class = "datepicker" })
            @Html.ValidationMessageFor(model => model.EndDate)
        </div>
        <div class="editor-label">
            Distance House - Work (km) :
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.HouseToWorkKilometers)
            @Html.ValidationMessageFor(model => model.HouseToWorkKilometers)
        </div>
        <div class="editor-label">
            Category :
        </div>
        <div class="editor-field">
            @Html.DropDownList("Id_ProductPackageCategory", "Choose one ...")
            @Html.ValidationMessageFor(model => model.Id_ProductPackageCategory) <a href="../ProductPackageCategory/Create">
                Add a new category?</a>
        </div>
        <div class="editor-label">
            Upgrade? :
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Upgrade)
            @Html.ValidationMessageFor(model => model.Upgrade)
        </div>
        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
}
<div>
    @Html.ActionLink("Back to List", "Index")
</div>
    public ActionResult Edit(long id = 0)
    {
        Person person = db.Persons.Single(p => p.Id_Person == id);
        if (person == null)
        {
            return HttpNotFound();
        }
        ViewBag.Id_ProductPackageCategory = new SelectList(db.ProductPackageCategories, "Id_ProductPackageCategory", "Name", person.Id_ProductPackageCategory);
        return View(person);
    }

    //
    // POST: /Person/Edit/5

    [HttpPost]
    public ActionResult Edit(Person person)
    {

        ViewBag.Id_ProductPackageCategory = new SelectList(db.ProductPackageCategories, "Id_ProductPackageCategory", "Name", person.Id_ProductPackageCategory);

        if (ModelState.IsValid)
        {
            ModelStateDictionary errorDictionary = Validator.isValid(person);

            if (errorDictionary.Count > 0)
            {
                ModelState.Merge(errorDictionary);
                return View(person);
            }

            db.Persons.Attach(person);
            db.ObjectStateManager.ChangeObjectState(person, EntityState.Modified);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        return View(person);
    }