Issue
I needed to format some dates on a View and could not remember the syntax.Define in your model a readonly variable
public String startDateFormatted { get { return String.Format("{0:dd/MM/yyyy}", startDate); } }
Then in the razor syntax just use DisplayForDisplayFor(modelItem => item.startDateFormatted)
OR
You can use the assign the date formatting attributes on the property of the model
[DisplayFormat(DataFormatString="{0:dd/MM/yyyy}")]
public DateTime? startDate { get; set; }
[DisplayFormat(DataFormatString="{0:dd/MM/yyyy}")]
public DateTime? startDate { get; set; }
No comments:
Post a Comment