【发布时间】:2016-01-04 13:06:13
【问题描述】:
我正在使用 bootrap 日期时间选择器来允许用户输入日期,如下所示:
<div class="form-group">
<label for="end">Start date:</label><br />
<div class='input-group date' id='dt1'>
@Html.TextBox("StartDateFilter", null, new { @class = "form-control" })
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
<script type="text/javascript">
$('#dt1').datetimepicker({
format: 'L',
locale: 'en-GB'
});
</script>
然后,该日期将作为以下方法签名中的参数:
public ActionResult Index(string sortOrder, string sortBy, string currentFilter, string searchString, string filterType, int? itemDisplay, int? page, DateTime? startDateFilter, DateTime? endDateFilter)
但是,文本框中的日期显示为 DD/MM/YYYY,但传递为 MM/DD/YYYY,这会导致一些格式错误和解析错误。如何将参数中的 DateTime 对象的格式或本地更改为 DD/MM/YYYY。
我已经在 system.web 下的 web.config 文件中添加了以下内容:
<globalization culture="en-GB" uiCulture="en-GB" />
提前致谢。
【问题讨论】:
标签: c# asp.net-mvc validation datetime bootstrap-datetimepicker