考虑以下模型:
public class ExportRequestsFilter {
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime? StartDate { get; set; }
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime? EndDate { get; set; }
...
使用各自的视图:
<script type="text/javascript">
$(document).ready(function () {
$(".datepicker").datepicker({ dateFormat: 'dd/mm/yy' }); // this is the datepicker equivalent to dd/MM/yyyy
});
</script>
...
<% using (Html.BeginForm(FormMethod.Post)) {%>
...
<%: Html.TextBox("StartDate", Model.StartDate, new { @class = "datepicker" })%><br />
<%: Html.TextBox("EndDate", Model.EndDate, new { @class = "datepicker" })%>
<input type="submit" class="buttonLink" name="submitButton" value="<%: Html.Resource("Preview") %>" />
当 StartDate TextBox 上的数据为 2/4/2012 时,是否有充分的理由将UpdateModel()
StartDate 设置为 2012 年 2 月 4 日而不是 2012 年 4 月 2 日?