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

Post datetime: wrong culture from inline editing

3 Answers 674 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Altitudo
Top achievements
Rank 2
Altitudo asked on 07 Aug 2018, 05:06 PM

I've a asp net core 2.0 web application with razor view. I've a grid with webapi datasource.

I've added and configured the UseRequestLocalization (in the Startup.Configure)

01.var enUSCulture = new CultureInfo("en-US");
02.var supportedCultures = new[]
03.    {
04.        enUSCulture,
05.        new CultureInfo("it-IT")
06.    };
07. 
08.app.UseRequestLocalization(new RequestLocalizationOptions
09.{
10.    DefaultRequestCulture = new RequestCulture(enUSCulture),
11.    // Formatting numbers, dates, etc.
12.    SupportedCultures = supportedCultures,
13.    // UI strings that we have localized.
14.    SupportedUICultures = supportedCultures
15.});

 

In the _Layout.cshtml I've included the culture and messages javascript files

01.@{
02.    var currentCultureString = System.Globalization.CultureInfo.CurrentUICulture.ToString();
03.}
04. 
05.<script src="~/lib/kendo-ui/js/cultures/kendo.culture.@(currentCultureString).min.js"></script>
06.<script src="~/lib/kendo-ui/js/messages/kendo.messages.@(currentCultureString).min.js"></script>
07. 
08.<script type="text/javascript">
09.    kendo.culture('@currentCultureString');
10.    $(document).ready(function () {
11.        kendo.culture('@currentCultureString');
12.        //server culture:       @System.Globalization.CultureInfo.CurrentCulture.ToString()
13.        //server ui culture:    @System.Globalization.CultureInfo.CurrentUICulture.ToString()
14.    });
15.</script>

 

I've verified the generated html and I can see the right culture (it-IT) with right datetime format both in display mode and inline edit mode (with datepicker in EditorTemplates). --> see the attachment

However when I click on save button, the put operation is done using en-US culture and goes wrong in the webapi --> see the attachment

Any idea as to what I am doing wrong?

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 10 Aug 2018, 08:41 AM
Hello, Paolo,

Thank you for the provided information.

In general, the dates will be sent based on the browser culture which is different than the kendo culture.

In cases like this, we recommend parsing the Date to the expected format before passing it to the server. This requires removing the current timezone format and then applying the desired one in this case "it-IT". It can be done using the parameterMap:

https://docs.telerik.com/kendo-ui/api/javascript/data/datasource/configuration/transport.parametermap

A similar approach is used in this demo:

https://docs.telerik.com/kendo-ui/controls/data-management/grid/date-formats#allowing-the-user-to-customize-the-timezone

The following StackOverflow thread can also prove helpful:

https://stackoverflow.com/questions/28224846/kendo-grid-sending-date-in-wrong-format

Regards,
Stefan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Altitudo
Top achievements
Rank 2
answered on 14 Sep 2018, 01:34 PM

Thanks Stefan for your reply, and sorry for this late one.

how does telerik detect the current browser culture? I would like to use the same way to detect the culture used in the serialization.
I have a lot of views with different grids and models. Handling every date property is very expensive and error prone, so I'm trying to keep your solution as the last chance..

0
Stefan
Telerik team
answered on 19 Sep 2018, 08:49 AM
Hello, Paolo,

The Kendo UI only sets to current culture for its widgets and does not detect the browser one. The automatically makes this conversation, that is why a custom approach is used to convert them.

As handling date is a complex task that depends on many variables our recommendation is to use UTC on the client and on the server:

https://docs.telerik.com/aspnet-mvc/helpers/grid/how-to/editing/utc-time-on-both-server-and-client

We understand that with many Grid converting all of them is not an easy task, but when UTC is used on the client and on the server this can resolve many issues when the app can be used in many different timezones.

Regards,
Stefan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Altitudo
Top achievements
Rank 2
Answers by
Stefan
Telerik team
Altitudo
Top achievements
Rank 2
Share this question
or