Why a jquery datepicker change days for months?

↘锁芯ラ 提交于 2019-12-11 00:23:03

问题


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>

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!


回答1:


In web.config add the following:

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

It should change the default date parsing.



来源:https://stackoverflow.com/questions/19279831/why-a-jquery-datepicker-change-days-for-months

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!