BUDDHIKA
BUDDHIKA

Reputation: 316

Kendo MVC Date Picker - Loading date in yy/MM/dd format

Im trying to display (load date picker with a value for editing) a date value with in cshtml view in 'yy/MM/dd' format using Kendo MVC Date picker, but it does not show the value.

Below is the ASP.NET MVC model - Date Property,

[Display(Name = "Installation Date")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yy/MM/dd}")]
public DateTime? InstallationDate { get; set; }

Below is the section of the cshtml view where I try to render the date value with in the date picker in 'yy/MM/dd' format.

@(Html.Kendo().DatePickerFor(model => model.InstallationDate)
    .Format("yy/MM/dd")
    .HtmlAttributes(new { @class = "form-control dpClass", style = "width: 100%", title = 
    "Installation Date", onkeydown = "return false;" })                    )

Here is what the HTML that was generated for the date picker.

<input class="form-control dpClass k-input" data-val="true" data-val-date="The field Installation 
Date must be a date." id="InstallationDate" name="InstallationDate" onkeydown="return false;" 
style="width: 100%" title="Installation Date" type="text" 

value="16/05/16" 

data-role="datepicker" 
role="combobox" aria-expanded="false" aria-owns="InstallationDate_dateview" aria-disabled="false" 
aria-readonly="false">

Please note that value is rendered above for 2016 May 16 as - value="16/05/16". Even though this value is rendered in HTML, for some reason, it does not show in the view. Please see the below screen shot.

enter image description here

But, if I manually select a date from date picker, it is displayed properly in the date picker in yy/mm/dd format. For an example, if I select 2016 May 17, it gets displayed correctly (below screen).

enter image description here

Question - Why is the date picker is not loading the date value in specified format? Any help on this much appreciated.

Upvotes: 0

Views: 936

Answers (0)

Related Questions