为什么jquery datepicker会改变几个月的日期? [英] Why a jquery datepicker change days for months?

查看:112
本文介绍了为什么jquery datepicker会改变几个月的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究MVC项目,并且使用jquery datepicker我在帖子中遇到了问题。
我使用包含文本框和jquery函数的局部视图。像这样:

I'm working on MVC project, and using the jquery datepicker I have problems in the post. I use a partial view which contains the text box and the jquery function. Like this:

 @model Nullable<System.DateTime>
<div class="row-fluid input-append">
    @if (Model.HasValue && Model.Value != DateTime.MinValue)
    {
        @Html.TextBox("", String.Format("{0:dd/MM/yyyy}", Model.Value), new { @class = "input-small date-picker",@readonly = true, style = "cursor:pointer; background-color: #FFFFFF; text-align: center;" })
    }
    else
    {
        @Html.TextBox("", String.Format("{0:dd/MM/yyyy}", ""), new { @class = "input-small date-picker", @readonly = true, style = "cursor:pointer; background-color: #FFFFFF; text-align: center;" })
    }
</div>

@{
    string name = ViewData.TemplateInfo.HtmlFieldPrefix;
    string id = name.Replace(".", "_");
}

<script type="text/javascript">
    $('#@id').datepicker({
        dateFormat: 'dd/mm/yy',
        todayHighlight: true,
        clearBtn: true,
        forceParse: true,
        autoclose: true,
    });
</script>

当我格式化datepicker以选择日期/月/年的日期,以及当我选择一个约会格式没关系!我的意思是,我在日历中选择了8月5日,文本框显示05/08/2013,但是当点击保存时会出现问题,因为在控制器中,日期的值会在几天到几个月内更改!
谢谢!

When I format the datepicker to pick the date in days/months/years, and when I pick a date the format it's ok! I mean, I select 5th of august in the calendar, and the textbox shows 05/08/2013, but the problem arise when a click save because, in the controller, the value on the date is changed days to months! Thanks!

推荐答案

web.config 中添加以下:

<system.web>
    <globalization culture="en-GB" uiCulture="en-GB" />
</system.web>

它应该更改默认日期解析。

It should change the default date parsing.

这篇关于为什么jquery datepicker会改变几个月的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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