Display only Date in @Html.DisplayFor() in MVC

I didn’t use @html.DisplayFor().Instead of this I use

@Convert.ToString(string.Format("{0:dd/MM/yyyy}", item.chekin_on_after))

And it works perfectly.


Try to use below attribute in your model class.

[DisplayFormat(ApplyFormatInEditMode = true,DataFormatString = "{0:MM/dd/yyyy}")]
public DateTime chekin_on_after { get; set; }

Hope it helps..


You can use this function in your controller before populating the data to model :

public static System.DateTime ParseDate(string value, string style)
{
    DateTime blankDate = default(DateTime);
    if ((value != null & value.Length > 0)) {
        string formattedDate = Strings.Format(Convert.ToDateTime(value), style);
        return formattedDate;
    } else {
        return blankDate;
    }
}

Where value is your: 10/22/2014 12:00:00 AM and style is :"MM/dd/yyyy" or something as you want