我正在研究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>
当我格式化日期选择器以选择日期/月/年的日期时,当我选择日期时,格式就可以了!我的意思是,我在日历中选择了8月5日,文本框显示05/08/2013,但是当点击保存时会出现问题,因为在控制器中,日期的值会在几天到几个月内更改! 谢谢!
答案 0 :(得分:2)
在web.config
中添加以下内容:
<system.web>
<globalization culture="en-GB" uiCulture="en-GB" />
</system.web>
它应该更改默认日期解析。