I have a custom helper for a DateTime attribute in my model.
The helper return Html for 3 selects one for day, one for months and the lasts one for years.
I have :
public static MvcHtmlString DateFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression)
{
...
}
And I’m wondering how to linked the choice of the user when I submit the form into my model dateTime Attribute.
In fact I would like to do the same thing as the EditorFor Helper. If I have for example :
@Html.EditorFor(model => model.UserName)
Where userName is a sring. It return a textBox html input and when I submit my form the userName attribute is automatically filled with the field value.
You could write a custom model binder for the DateTime type and a custom editor template to present the UI however you like. Scott Hanselman
blogged about this. And here’s anupdated version.