I am using ASP.NET MVC2 with MvcContrib.FluentHtml to do form binding.
I want to bind a DateTime format to a textbox with specific datetime format.
<%=this.TextBox(c => c.date_a).Class("readonly text-box") %>
// PS. c.date_a is a DateTime
gives me
<input type="text" value="5/9/2009 12:00:00 AM" name="date_a" id="datea" class="readonly text-box">
However, I'd like to override the default datetime format. e.g.
value="2009-5-9"
value="9-5-09"
value="09May9"
I know I can override the value by specific a value, however, the date should also bind to the object class on POST the form.
How to do "minimum" code to override the default datetime format of a specific field on UI?
I don't know if this work with MvcContrib MvcContrib.FluentHtml but without it, it is very simple, add to your model property
[DisplayFormat(DataFormatString="{0:MM/dd/yyyy}", ApplyFormatInEditMode=true)]
and in your view
m.DateProperty) %>
I Don't know if MvcContrib uses Attributes but if it doesn't, it should, that way, you'll always have your date the same format, specifying the format only once...
hope this help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With