Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC model binder not parsing ISO DateTime correctly
    text
    copied!<p>I've been trying to post a form to my controller:</p> <pre><code>Id=0&amp;ReportDate=2010-08-09T00%3A00%3A00&amp;SampleText=Save </code></pre> <p>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?</p> <p>Edit: If I set another variable, <code>ReportDateString</code>, send the string to the controller and do a <code>DateTime.Parse()</code>, it works fine. However, I'd really like to be able to bind the DateTime directly as this feels hacky.</p> <p>Edit 2: Hereis my controller code:</p> <pre><code>public void CreateTest(MyObject myObject) { myObjectRepository.Update(rootObject); } </code></pre> <p>And my object:</p> <pre><code>public class MyObject { public int Id { get; set; } public string SampleText{ get; set; } public DateTime ReportDate { get; set; } } </code></pre> <p>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.</p> <p>Edit 3: Form:</p> <pre><code>&lt;form id="testform" method="post"&gt; &lt;input type="hidden" name="Id" value="0" /&gt; &lt;input type="hidden" name="ReportDate" value="2010-08-09T00-00-00" /&gt; &lt;input type="text" name="SampleText" value="Test"/&gt; &lt;button id="saveButton"&gt;Save&lt;/button&gt; &lt;/form&gt; </code></pre> <p>Javascript:</p> <pre><code>$('#saveButton')live('click', function(e) { $.post('CreateTest', $('#testform').serialize()) }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload