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

Wrong date format in treeView read action in controller

4 Answers 61 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Janusz
Top achievements
Rank 1
Janusz asked on 30 Nov 2018, 08:13 AM

Hi,
I've got a problem with kendo culture and treeView read action. 

I've got bilingual application, with en-US and pl-PL culture, which I set like this:
Client side: (var culture = "pl-PL" or "en-US")

<script src="@Url.Content("~/Scripts/kendo/cultures/kendo.culture." + culture + ".min.js")"></script>
    <script src="@Url.Content("~/Scripts/kendo/messages/kendo.messages." + culture + ".min.js")"></script>
    <script>kendo.culture("@culture");</script>

Server side: (ex.: CultureInfo cultureInfo = new CultureInfo("pl-PL");)

Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = cultureInfo;

It seems to work well.

I've got a view with grid and treeView. Both has read action with additional data, getting like this:

.Read(read => read.Action(@"ReadOfertyTree", @"Oferty").Data(@"filterGrid")) <- treeView
(...)
.Read(read => read.Action(@"ReadOferty", @"Oferty").Data(@"filterGrid")) <- grid
(...)
function filterGrid() {
        return {
            dataOd: dataOd,
            dataDo: dataDo,
            klient: klient,
            zamow: zamow
        };
    }

dataOd and dataDo both are read from kendoDatePicker. In both cases I can see in network in my browser, that date is sending in format dd.MM.yyy for pl culture and MM/dd/yyyy for en culture. In case of en, everything is allright BUT in pl case I faced with strange behaviour.

In controller's action read for grid I got dates:
1.11.2018 is read as 1st of november 2018
30.11.2018 is read as 30th of november 2018
BUT in treeView read action I've got:
1.11.2018 is read as 11th of january 2018
30.11.2018 is read as null

I don't set culture in any other places. Both controlls are in the same cshtml file and both read action in the same controller. What's wrong?

 

4 Answers, 1 is accepted

Sort by
0
Janusz
Top achievements
Rank 1
answered on 30 Nov 2018, 08:35 AM
(Is there a way to edit my post?)
I've notticed that read action from grid is sending via POST and from treeView via GET. If i set POST for treeView too, everything works fine (dates are interpreated right). What is the reason,that http methods are different? 
0
Veselin Tsvetanov
Telerik team
answered on 03 Dec 2018, 02:20 PM
Hello Janusz,

I am afraid that the system would not allow you to edit your initial post. Nevertheless, I believe that we can discuss and explain the case in question, without altering its content.

So, answering to your question. The DataSource implementation of the TreeView sends a request of different type (GET) that the request sent from the Grid DataSource (POST) because the default Read() for the Grid would also contain a DataSourceRequest object. In order to send that object to the server as a request body (instead of sending that data as a query string), the DataSource uses a POST request.

The TreeView DataSource, on the other hand, does not send a DataSourceRequest object. Therefore, by default it uses a simpler GET request.

Regards,
Veselin Tsvetanov
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
Janusz
Top achievements
Rank 1
answered on 10 Dec 2018, 01:16 PM
Ok, but, despite the fact, that there are two various types of http method, why the dates are read differently?
0
Veselin Tsvetanov
Telerik team
answered on 12 Dec 2018, 10:27 AM
Hello Janusz,

The observed is the default behaviour of the .Net MVC application in the discussed case. The Form Data post request will be sent as a culture independent UTC Date object string. It will not bring information about the timezone / culture it has been created in. Here you could find some more information on that topic.

The query string of the GET method, however, will send a string representation of the date to the server. The server will try to parse that date using its default date format (apparently it is the en-US format in Visual Studio in the discussed case). That is why the parse fails and the difference observed is present. Using the .toISOString() call on the date objects in that request should sent proper data to the server:
return {
  dataOd: dataOd.toISOString(),
  dataDo: dataDo.toISOString(),
  klient: klient,
  zamow: zamow
};

Regards,
Veselin Tsvetanov
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
TreeView
Asked by
Janusz
Top achievements
Rank 1
Answers by
Janusz
Top achievements
Rank 1
Veselin Tsvetanov
Telerik team
Share this question
or