1

I've a datepicker control in my website, when I click into a textbox, the datepicker is displaying:

enter image description here

But when I'm clicking into a date, I have a problem to display the date:

enter image description here

The year is displaying two times... But I don't know why... I've followed this tutorial

Can you help me to find why the date's year is displaying two times please ?

Date.cshtml

@model DateTime

<script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.js")" type="text/javascript">    </script>
<link href="@Url.Content("~/Content/themes/base/jquery.ui.all.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/EditorHookup.js")" type="text/javascript">    </script>

@Html.TextBox("", Model.ToString("dd/MM/yyyy"),
              new { @class = "date" })

** TODO Wire up the date picker! **

EditorHookup.js

/// <reference path="~/Scripts/jquery-1.5.1.js" />
/// <reference path="~/Scripts/jquery-ui-1.8.11.js" />
$(document).ready(function () {
$(".date").datepicker({
    //      buttonImage: "/content/images/calendar.gif",
    //      showOn: "both",
    //      defaultDate: $("#calendar-inline").attr('rel')
    showAnim: 'slideDown',
    dateFormat: 'dd/mm/yyyy'

});
});

Create.cshtml (View)

    <div class="editor-label">
        @Html.LabelFor(model => model.Date)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Date)
        @Html.ValidationMessageFor(model => model.Date)
    </div>

Model class

public class Reservation
{
    [Display(Name = "Date")]
    [Column("Date")]
    [DataType(DataType.Date)]
    [DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)]
    public DateTime Date { get; set; }
}

And finally Controller's create method

// GET: /Reservation/Create

    public ActionResult Create()
    {
        return View(new Reservation { Date = DateTime.Now.Date});
    } 

1 Answer 1

4

The problem might be in your EditHookup.js in this line:

dateFormat: 'dd/mm/yyyy'

Try changing to:

dateFormat: 'dd/mm/yy'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.