Question : how to format date with Html.TextBoxFor helper ?

how to format date which is displayed using  Html.TextBoxFor helper  class.

Answer : how to format date with Html.TextBoxFor helper ?

The issue is that the String.Format("{0:MM/dd/yyyy}", Model.ExpirationDate) bit above is the TemplateName parameter of the TextBoxFor method. The view engine won't be able to find a template which matches the date.

What you need to do is decorate your model

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

and then use the following in your view

<%= Html.EditorFor(model => model.DateRequired)%>
Random Solutions  
 
programming4us programming4us