考虑以下型号:设置日期时间格式的UpdateModel
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") %>" />
有没有什么好的理由时,就开始日期文本框的数据是2012年2月4日,UpdateModel()
将StartDate设置为2012年2月4日,而不是2012年4月2日?
你可以发表一个样本,我该如何告诉UpdateModel我想使用的文化? – dcarneiro 2012-04-10 16:31:57