MVC jQuery datepicker返回dd/MM/yyyyyyyy [英] MVC jQuery datepicker returns dd/MM/yyyyyyyy

查看:65
本文介绍了MVC jQuery datepicker返回dd/MM/yyyyyyyy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用POCO模型将jQuery Datepicker添加到EditFor中. 但是,当我在DatePicker中选择一个日期时,浏览器中的行为很奇怪:文本框以以下格式显示日期:"dd/MM/yyyyyyyy" 这里是一个示例代码,它复制了该代码: 人员模型:

I've added a jQuery Datepicker to an EditFor with a POCO model. But I’m having a weird behaviour in the browser when I select a date in the DatePicker: the textbox presents the date in this format: "dd/MM/yyyyyyyy" Here a sample code that reproduces that: The Person model:

public class PersonModel
{
    public string PersonID { get; set; }
    public string Nombre { get; set; }

    [DataType(DataType.Date)]
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
    public DateTime DoB { get; set; }
}

视图:

<div class="form-group">
    @Html.LabelFor(model => model.Nombre, new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        @Html.EditorFor(model => model.Nombre)
        @Html.ValidationMessageFor(model => model.Nombre)
    </div>
</div> 

DateTime.cshtml视图

The DateTime.cshtml view

@model System.DateTime
@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue,
                    new { data_datepicker = true });

test.js

    $(document).ready(function () {
    $('#DoB').datepicker({
        dateFormat: "dd/mm/yyyy"
    });
});

将模型发送到视图的创建动作

The Create Action that sends the model to the view

public ActionResult Create()
    {
        var person = new PersonModel();
        person.PersonID = Guid.NewGuid().ToString();
        person.DoB = DateTime.Today.AddYears(-30);
        return View(person);
    }

所有css和js文件都添加到BundleCondig.cs文件中. 感谢您的帮助.

All css and js files are added in the BundleCondig.cs file. Thanks for your help.

推荐答案

datepicker日期格式为:

datepicker date format is:

dateFormat: "dd/mm/yy"

http://jqueryui.com/resources/demos/datepicker/date- format.html

这篇关于MVC jQuery datepicker返回dd/MM/yyyyyyyy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆