Listview and different cultures problem.

2 posts, 0 answers
  1. Jan Olsmar
    Jan Olsmar avatar
    35 posts
    Member since:
    Mar 2006

    Posted 17 Mar 2013 Link to this post

    I have MVC 4 project and using a listview with edit.
    When I use en-US culture everything work as aspected. I got problem with my native sv-SE culture however. Firt I used the 2012-3 release but after the problem I tryed the 2013 release unfortunately with same result.
    Problem with sv-SE.
    fields with decimal comma seperator does not work (both decimal and double) cant save to the database. No validation errors.
    I tested with culture fr-FR same result.
    SO I tested with de-DE and suddenly the save to database worked. However all values was 10 times bigger. eg. 14,5 was saved as 145.
    The errors was only when I use decimal comma value bigger than 0. eg 10,0 works but 10,xx does not.
    I asume Kendo MVC cant be so bad so I have to do something wrong, but I cant find the error.

    In all test I change webconfig to use the the culture I test. I load the coresponding kendo js too and I set the kendo culture.
    I run my machine in my native culture and the database have also Swedish collation.

    If I use a "normal" edit and save all works as it shoud do.

    Do I need some other js to get the Kendo UI json transport to work for other cultures than US.

    If I cant work this out maybe my try just will be a try. Hopefully not as I invested a lot of time in this in the project in question.

    Thanks in advance.

  2. Daniel
    Daniel avatar
    2177 posts

    Posted 20 Mar 2013 Link to this post

    Hello Jan,

    The reason for the problem is that there is only type number in JavaScript so all numbers are formatted as JavaScript numbers. The problem can be avoided either by using a custom model binder that uses invariant culture for parsing the numbers or by formatting the numbers in the request Data function:

    .Update(update => update.Action("action", "controller").Data("convertNumbers"))
    function convertDecimals(data) {
        for (var property in data) {
            var value = data[property];
            if (typeof value === "number") {
                if (value % 1 == 0) {
                    data[property] = value.toString();
                else {
                    data[property] = kendo.toString(value, "n");
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top