1

I had the following problem. In my database I have an attribute which type is "float". When I create the model with Entity Framework, the same attribute is represented by a "double" field.

Here's the thing. In the view, if I write for example "23,22" the data annotation says it is not a number, and if I write "23.22" passes the validation but the attribute's value is null when it gets to the controller.

Any idea why does it happen? I've been looking for information, but nothing useful yet.

Thanks in advance!

Edit: I add the code where I use that attribute.

In the model class it is like this:

    public class TestObject{

         ....
         public Nullable<double> attribute { get; set; }
         ....
        }

In the view:

        @Html.EditorFor(m => m.attribute)

And in the controller:

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Test(TestObject test)
    {
     ....
        return View();
    }

If I write "23.22", when I access the attribute value in the controller, it is null.

4

1 回答 1

1

作为一个可行的解决方案,您可以更改 jQuery 文化以允许逗号分隔符而不是点。在这种情况下,双精度将正确传递。

//For example German culture uses comma. Just add this line:

    <script>
    Globalize.culture("de-DE");
    </script>
于 2013-10-03T07:16:13.320 回答