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

前端 未结 5 1231
被撕碎了的回忆
被撕碎了的回忆 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:51

    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()) })
    

提交回复
热议问题