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

Cannot use a custom date format in MVC

1 Answer 175 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Ben
Top achievements
Rank 1
Ben asked on 25 May 2017, 06:21 AM

I have been trying to make Kendo MVC be able to display dates like "March 5 2013" using Kendo MVC. 

 

I am also using JQuery Validator. It is very unclear to me how the validator and the date format work together, and I cannot see any documentation for how this works, and can be adjusted. 

Code in the CSHTML file : 

 

@(Html.Kendo().DatePickerFor(m => m.StartDate).Format("yyyy-MM-dd") 

in my CS m.StartDate is just a .net DateTime object. 

I have found that no matter what, I cannot get the dates to bind correctly in chrome unless I use the date format above (If I do not supply dates in the above format, the date field is blank)

 

I have added the locale specific scripts, so that doesn't appear to be an issue.

I have also tried applying 

[DisplayFormat(DateFormatString="MMMM dd yyyy")] to the StartDate object being passed through in my model. 

 

It seems like the Date handling for non locale specific dates in  Kendo is really badly broken - I am hoping that I am missing something. 

 

Looking at the data being passed to the browser, it appears that it uses the DateFormatString to define how to send the data across the wire, and then relies on the client JavaScript having the correct locale defined so that the two match. This in my opinion is just asking for trouble, and very fragile.

Is there a way that we can define a single format (regardless of locale ) to send across the wire, and the use the displayformat ONLY to display the data?

I have searched the forums, and looked through the documentation, but alas, I cannot see a way to make this work sensibly. 

There does not seem to be a custom date format example anywhere that works :(

Please correct me if I am wrong. 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 29 May 2017, 08:02 AM
Hello Ben,

For the mentioned issue with the format and not displaying the date in Chrome.

This is a known issue related to how Chrome is handling input elements with type=" date".

I can suggest to manually set the type attribute to text in order to be able to set different formats:

HtmlAttributes(new { style = "width: 100%", type="text" }

If this help to set the date in the desired format, please advise if another issue still occurs?

As for the date format which is sent to the server, the widget will send the date in the same format they are received, the format property is affecting only the visualisation of the date. 

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
Tags
Date/Time Pickers
Asked by
Ben
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or