I've been trying to post a form to my controller:
Id=0&ReportDate=2010-08-09T00%3A00%3A00&SampleText=Save
That's the XHR post that is sent, my controller picks up all the properties except ReportDate, instead setting it to the .NET epoch DateTime. Any ideas?
Edit: If I set another variable, ReportDateString
, send the string to the controller and do a DateTime.Parse()
, it works fine. However, I'd really like to be able to bind the DateTime directly as this feels hacky.
Edit 2: Hereis my controller code:
public void CreateTest(MyObject myObject) {
myObjectRepository.Update(rootObject);
}
And my object:
public class MyObject {
public int Id { get; set; }
public string SampleText{ get; set; }
public DateTime ReportDate { get; set; }
}
If I set a debug, I can see that the model binder successfully binds all the properties on my post except the DateTime which it sets to the epoch date.
Edit 3: Form:
<form id="testform" method="post">
<input type="hidden" name="Id" value="0" />
<input type="hidden" name="ReportDate" value="2010-08-09T00-00-00" />
<input type="text" name="SampleText" value="Test"/>
<button id="saveButton">Save</button>
</form>
Javascript:
$('#saveButton')live('click', function(e) {
$.post('CreateTest', $('#testform').serialize())
});