John John
John John

Reputation: 1

The default Date format is being displayed after i change my @Html.EditorFor to @Html.TextBox

I have defined the date format on my model class as follow:-

[DisplayFormat(DataFormatString = "{0:f}", ApplyFormatInEditMode = true)]
        [Display(Name = "Date Taken")]
        public DateTime DateTaken { get; set; }

and it was displayed properly on the @Html.EditorFor(model => model.DateTaken), but after i changed the editorfor to be @Html.TextBox("DateTaken", null, new { @id = "DateTaken"+item.ToString() }) ; The date format is now being displayed as 03/05/2012 instead of 05 May 2012,, so how can i apply the intended date format on the @Html.TextBox

BR

Upvotes: 0

Views: 316

Answers (1)

Mike Henderson
Mike Henderson

Reputation: 26

Without getting too fancy you could just do this:

@Html.TextBox("DateTaken", Model.DateTaken.ToString("d MMM yyyy"), 
                           new { @id = ... }) 

Upvotes: 0

Related Questions