I have a standard asp.net mvc 4 view with a form that has some editable fields, including a DataTime selection. When the form is posted back to the controller, the DateTime always shows up as the minimum value for DateTime 1/1/0001, even though a valid date is successfully sent to the client or selected on the client.
I'm guessing the DefaultModelBinding is messing this up, but I'm not sure why or how. In my web.config I have the following for globalization:
<globalization enableClientBasedCulture="true" uiCulture="auto" culture="auto"/>
Here is my ActionResult in the controller that receives the post:
[HttpPost]
public virtual ActionResult Edit(KBUser kbuser)
{
if (this.ModelState.IsValid)
{
//save the user
m_userRepo.UpdateUser(kbuser);
return RedirectToAction(MVC.Users.Index());
}
else
{
return View(kbuser);
}
}
Here is the relevant part of the View:
@model KBMaxLive.Domain.KBUser
@using (Html.BeginForm("Edit", "User", new { idUser = Request["idUser"] }, FormMethod.Post, new { id = "form" }))
{
<fieldset>
<legend>@Engine.Resources.KBMaxLive.Account</legend>
<div class="field-column-container">
<div class="field-column">
<div class="field-container">
@Html.LabelFor(u => u.CreatedDate)
@Html.TextBoxFor(u => u.CreatedDate, new { @class = "k-textbox", @readonly = "readonly" })
@Html.ValidationMessageFor(u => u.CreatedDate)
</div>
</div>
</div>
</fieldset>
}
All properties of the model come in fine except for the datetime.
Any ideas on what's going wrong or how to debug this?