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> 

Model类

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

最后控制器的创建方法

// GET: /Reservation/Create 

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

的问题可能是你的EditHookup.js在这条线:

dateFormat: 'dd/mm/yyyy' 

尝试改变到:

dateFormat: 'dd/mm/yy' 
+1

+1自己蹲下这个洞。 – 2012-03-14 11:43:10

+0

你是对的!谢谢 ;) – Razor 2012-03-14 11:43:46