You can use DisplayTemplates and EditorTemplates to define how properties of a particular type are displayed.
In the Views > Shared folder create a folder called DisplayTemplates and another called EditorTemplates you can then add custom templates to these for each different type of property you want to display. The templates work in a similar way to a partial.
I have one for DisplayTemplate for DateTime
@model DateTime
@if (Model.Value.Year == 1) {
@Html.TextBox("", "")
} else {
@Html.TextBox("", (Model.Value.ToString("dd/MM/yyyy")))
}
<span class="help-text">dd/mm/yyyy</span>
Here is an EditorTemplate for TimeSpan
@model TimeSpan
@Html.DropDownList("", Enumerable.Range(0, 30)
.Select(i => new SelectListItem { Value = i.ToString(),
Text = i.ToString(), Selected = Model.Days == i })) days
@Html.DropDownList("", Enumerable.Range(0, 24)
.Select(i => new SelectListItem { Value = i.ToString(),
Text = i.ToString(), Selected = Model.Hours == i })) hours :
@Html.DropDownList("", Enumerable.Range(0, 60)
.Select(i => new SelectListItem { Value = i.ToString(),
Text = i.ToString(), Selected = Model.Minutes == i })) minutes :
@Html.DropDownList("", Enumerable.Range(0, 60)
.Select(i => new SelectListItem { Value = i.ToString(),
Text = i.ToString(), Selected = Model.Seconds == i })) seconds
I would caution that you can spend a lot of time try to get EditorForModel to work exactly how you want it but there will always be cases where it doesn't work quite right and you have to resort to hand coding.
We now use an HTML helper to wrap our custom HTML around each property this can work nicely alongside the custom templates described but allows a lot more flexibility too. We used this page as inspiration for our custom HTML wrappers. ASP.NET MVC 3 Custom HTML Helpers- Best Practices/Uses See the answer with the highest number of up votes rather than the accepted answer.