【问题标题】:datepicker control: why the date's year is displaying two times?datepicker 控件:为什么日期的年份显示两次?
【发布时间】:2012-03-14 11:30:37
【问题描述】:

我的网站中有一个日期选择器控件,当我点击文本框时,日期选择器正在显示:

但是当我点击一个日期时,我无法显示日期:

年份显示两次...但我不知道为什么...我关注了这个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的create方法

// GET: /Reservation/Create

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

【问题讨论】:

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


    【解决方案1】:

    问题可能出在您的 EditHookup.js 这一行中:

    dateFormat: 'dd/mm/yyyy'
    

    尝试更改为:

    dateFormat: 'dd/mm/yy'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-07-25
      • 1970-01-01
      • 2016-03-27
      • 1970-01-01
      • 1970-01-01
      • 2011-08-03
      • 1970-01-01
      相关资源
      最近更新 更多