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

Initial value of datepicker selects wrong date in calendar

1 Answer 203 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Eric Kuijpers
Top achievements
Rank 1
Eric Kuijpers asked on 03 Apr 2015, 07:36 AM
I have a problem with the initial display of values in datepicker controls :

For example, April 3rd 2015 displays as 03/04/2015, but when opening the datepicker calendar, it has selected March 4th 2015 as date. Manually selecting April 3rd 2015 in the calendar again results in exactly the same display text (03/04/2015)...


Given a model which looks like this: 
[Display(Name = "Start Date")]
[DataType(DataType.Date)]
public DateTime StartDate { get; set; }
 

Configuration in web.config :
<system.web>
    <globalization uiCulture="en-GB" culture="en-GB"/>


Content in _Layout.cshtml
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="~/Content/Images/favicon.ico" type="image/x-icon" />
    <meta name="accept-language" content="en-GB" />

     @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @Scripts.Render("~/bundles/kendo/kendoscripts")
 
    @RenderSection("scripts", false)
    @RenderSection("scripts2", false)
 
    @Scripts.Render("~/bundles/Scripts/cultures/en")
    @Html.Kendo().DeferredScripts()
 
    <script type="text/javascript">
        var baseLocation = '@(Url.Content("~").TrimEnd('/'))';
        $(document).ready(function () {
            var data = $("meta[name='accept-language']").attr("content");
            kendo.culture(data);
        });
    </script>


BundleConfig :
bundles.Add(new ScriptBundle("~/bundles/Scripts/cultures/en")
              .Include("~/Scripts/kendo/cultures/kendo.culture.en-GB.min.js")
              .Include("~/Scripts/cultures/kendo.en-GB.js"));

Editor template :
@model DateTime?
 @(Html.Kendo().DatePickerFor(m => m).Deferred().HtmlAttributes(new { @class = "form-control k-datepicker-label-top" }))

cshtml page concerned:
<div class=" col-md-3">
    <div class="form-group">
@Html.LabelFor(m => m.StartDate)
@Html.EditorFor(m => m.StartDate)
   </div>
</div>

What am I missing here? 

1 Answer, 1 is accepted

Sort by
0
Eric Kuijpers
Top achievements
Rank 1
answered on 03 Apr 2015, 12:03 PM
Coffee did the trick. Moving the kendo.culture(data); outside of the $(document).ready solved the issue.
Tags
Date/Time Pickers
Asked by
Eric Kuijpers
Top achievements
Rank 1
Answers by
Eric Kuijpers
Top achievements
Rank 1
Share this question
or