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

前端 未结 5 1185
被撕碎了的回忆
被撕碎了的回忆 2021-02-20 11:25

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 acce

5条回答
  •  甜味超标
    2021-02-20 11:57

    DisplayFor expects an expression that identifies the object that contains the properties to display. It will use built in, or custom, templates to render that display. You trying to provide the display logic as that expression parameter, which is not valid.

    Use

    @String.Format("HH:mm:ss", Model.row.LastUpdateDate)
    

    or

    @Model.row.LastUpdateDate.ToString("HH:mm:ss")
    

提交回复
热议问题