This is a migrated thread and some comments may be shown as answers.

Listview and different cultures problem.

1 Answer 55 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Jan Olsmar
Top achievements
Rank 1
Jan Olsmar asked on 17 Mar 2013, 09:14 AM
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.
Jan

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 20 Mar 2013, 08:11 AM
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");
            }
        }
    }  
}
Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
ListView
Asked by
Jan Olsmar
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or