In MVC Razor view, I am trying to format a DateTime field to display time only. Using below code I am getting error "Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions."
<td>@(Html.DisplayFor(m=>row.LastUpdatedDate.ToString("HH:mm:ss")))</td>
Any help please what is causing this error and how to fix it ?
Thanks for your help.
I was having the same problem and I have resolved the problem. If you want to convert "LastUpdatedDate" to a specific format then you can try this:
@Html.TextBoxFor(m=>row.LastUpdatedDate,
new { @Value = Convert.ToString(row.LastUpdatedDate.ToShortDateString()) })
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