Following is the code extract:
@Html.TextBoxFor(m => m.CreatedSearchStartDate,
new { @Value=Model.CreatedSearchStartDate.Value.ToString("dd/MM/yyyy"),
@selectedDate =Model.CreatedSearchStartDate.Value.ToString("dd/MM/yyyy"),
@class="dateInput", @id="CreatedSearchStartDate" }
)
Following is relevant JQuery code
$("#CreatedSearchStartDate").each(function () {
var a = $(this).datepicker(
{
dateFormat: "dd/mm/yy",
defaultDate: new Date($(this).val())
})
});
The view is showing datepicker control, and it is functioning well. Also, the text box gets updated for underlying value (which I could check using Firebug). The only problem is that the underlying field in the model is not updated. Whereas, there are some other fields also in this model, which gets updated properly.
What could be the possible reason?
I have a feeling this is a culture problem. I haven’t experienced this problem myself, but I know others have. If there is a difference between the “culture settings” for your view compared to your application it can cause validation errors. Also it sounds like you need to make sure you are using post on your form submit for culture to be applied correctly. Check out these other posts and see if any of them help:
ASP.Net MVC model binding – how to change date format?
Custom DateTime model binder in Asp.net MVC