when I use this code in my view:
@Html.EditorFor(model => model.DateAdded)
I get the date formatted like this:
14-10-2012 11:44:34
Now I want to show only the date, and in this format.
2012-10-14
So I thought I'd use a EditorTemplate
But in a EditorTemplate
I start from scratch / I start with no HTML, and I have to eventually render this (which is what is rendered by .Net when i use this code@Html.EditorFor(model => model.DateAdded)
:
<input class="text-box single-line" data-val="true" data-val-date="The field DateAdded must be a date." data-val-required="The DateAdded field is required." id="DateAdded" name="DateAdded" type="datetime" value="14-10-2012 11:44:34" />
Can I somehow prevent myself from duplicating all these code (<input class="text-box single-line" data-val="true" data-val-date="The field DateAdded must be a date." data-val-required="The DateAdded field is required." id="DateAdded" name="DateAdded" type="datetime"
) because the framework might change it in the future, and then my template is stuck with that (old) code.
So what I want to say in my editor template is this: do everything you'd normally do, except format the value of the DateTime input differently.
Is that possible?
Typing this I realize I've made the assumption that for me to change the format of a DateTime in a @Html.EditorFor
method, I've to create a EditorTemplate. Is that assumption correct?