I got this code in my mvc-project:
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Massage45min)
</td>
<td>
@Html.DisplayFor(modelItem => item.Massage30min)
</td>
</tr>
}
Both modelItem
s are DateTimes. They are now getting displayed like this: 2014-03-23 08:00
and I would like only to display the time. Like this: 08:00
.
I thought this would do the trick:
@Html.DisplayFor(modelItem => item.Massage45min.ToShortTimeString())
But it generates this error:
An exception of type 'System.InvalidOperationException' occurred in System.Web.Mvc.dll but was not handled in user code
Additional information: Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.
Any ideas of how to display the DateTimes the way I want?