datepicker控件:为什么日期的年份显示两次?

时间:2012-03-14 11:30:37

标签: c# asp.net-mvc-3 datepicker

我的网站上有一个datepicker控件,当我点击一个文本框时,datepicker显示:

enter image description here

但是当我点击日期时,我有一个问题是显示日期:

enter image description here

这一年显示了两次......但我不知道为什么......我已经跟着这个tutorial

你能帮我找一下为什么日期的年份会显示两次吗?

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(查看)

    <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>

模型类

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

最后是Controller的创建方法

// GET: /Reservation/Create

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

1 个答案:

答案 0 :(得分:3)

问题可能出在此行的EditHookup.js中:

dateFormat: 'dd/mm/yyyy'

尝试更改为:

dateFormat: 'dd/mm/yy'