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:
我正在开发MVC项目,使用jquery datepicker我在文章中遇到了问题。我使用包含文本框和jquery函数的部分视图。是这样的:
@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!
当我格式化datepicker以天/月/年来选择日期,当我选择日期时,它的格式是ok的!我的意思是,我在日历中选择了8月5日,文本框显示了05/08/2013,但是当点击保存时,问题就出现了,因为在控制器中,日期的值会在几天到几个月之间变化!谢谢!
1 个解决方案
#1
2
In web.config
add the following:
在网络上。添加以下设置:
<system.web>
<globalization culture="en-GB" uiCulture="en-GB" />
</system.web>
It should change the default date parsing.
它应该更改默认的日期解析。
#1
2
In web.config
add the following:
在网络上。添加以下设置:
<system.web>
<globalization culture="en-GB" uiCulture="en-GB" />
</system.web>
It should change the default date parsing.
它应该更改默认的日期解析。