Consider the following Model:
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; }
...
With the respective View:
<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") %>" />
Is there any good reason for when the data on StartDate TextBox is 2/4/2012, UpdateModel()
sets the StartDate to 4 February 2012 instead of 2 April 2012?