DateFormat on DisplayFor not working
Posted
by
user335160
on Stack Overflow
See other posts from Stack Overflow
or by user335160
Published on 2012-06-20T02:56:06Z
Indexed on
2012/06/20
3:16 UTC
Read the original article
Hit count: 176
asp.net-mvc-3
I've set the Data Annotation for date, it works when I use the EditorFor but when I use the DisplayFor it is not working. The date is come from a collection of data. I get this format 8/13/2011 12:00:00 AM instead of 8/13/2011. What is wrong with the code.
Data Annotation for Date
[DisplayName("Date")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
[Required(ErrorMessage = "Date required.")]
public object EM_Date { get; set; }
View Code
@foreach (EventViewModel item in Model)
{
<tr>
<td class="AdBoxBodyRow1" style="text-align: center"> @Html.DisplayFor(modelItem => item.EM_Date) </td>
</tr>
}
© Stack Overflow or respective owner