我正在开发 MVC 项目,并使用 jquery datepicker 我在帖子中遇到问题。 我使用包含文本框和 jquery 函数的部分 View 。像这样:
@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>
当我格式化日期选择器以选择天/月/年的日期时,当我选择日期时,格式就可以了!我的意思是,我在日历中选择 8 月 5 日,文本框显示 05/08/2013,但是单击“保存”时会出现问题,因为在 Controller 中,日期值会从几天更改为几个月! 谢谢!
最佳答案
在web.config
中添加以下内容:
<system.web>
<globalization culture="en-GB" uiCulture="en-GB" />
</system.web>
它应该更改默认的日期解析。
关于c# - 为什么 jquery 日期选择器会改变几个月的日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19279831/