Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

formatting DateTime error "Templates can be used only with field access, property access, single-dimension array index.."

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.

like image 882
Toubi Avatar asked Oct 17 '13 02:10

Toubi


Video Answer


1 Answers

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()) })
like image 163
user3517975 Avatar answered Sep 21 '22 14:09

user3517975