How to format the Textbox with Date DisplayFormat in ASP.NET MVC Razor View ?

There are times when you want to format the textbox with date display format when developing a ASP.NET MVC Razor View application.

You can format the Textbox with Date DisplayFormat in ASP.NET MVC Razor View easily by setting the DisplayFormat attribute for the property in the Model and then bind ito the textbox.

Below is a sample sourecode demonstrating the formatting of Textbox with Date DisplayFormat in ASP.NET MVC Razor View .

Model

public class EmployeeModel

{

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:DD/MM/YYYY}")]

public DateTime DateOfBirth{ get; set; }

public string Name { get; set; }

}

View (Razor)

@Html.EditorFor(property => property.DateOfBirth)

Pin It

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>