1

我的模特

[UIHint("Date")]
[DisplayFormat(NullDisplayText="", DataFormatString = " {0:dd/MM/yyyy}")]
public DateTime Date { get; set; } // Date

显示模板日期

@model DateTime?
@Html.TextBox("", (Model.HasValue ? Model.Value.ToShortDateString() : string.Empty), new 
{

@class = "datepicker"

})
View

<div class="control-group">
@Html.LabelFor(model => model.Date, new { @class = "control-label" })
<div class="controls">
@Html.EditorFor(model => model.Date)
@Html.ValidationMessageFor(model => model.Date, null, new { @class = "help-inline" })
</div>
</div>

Javascript

 $.fn.datepicker.defaults.format = "dd/mm/yyyy";
    $('.datepicker').datepicker({
        autoclose: true,
        format: "dd/mm/yyyy"

    });

Datepicker 仍然不允许 dd/mm/yyyy 格式日期。几天以来,我一直在找出问题所在。

4

1 回答 1

0

您应该像这样从小写 dd/mm/yyy 更改为大写:

$(function(){
$('.datepicker').datetimepicker({
     autoclose: true,
    viewMode: 'years',
    format: 'DD/MM/YYYY',
});
于 2017-10-27T12:35:42.810 回答