Hi Team
I have a model, but to see the view its not showing correct format of date. I need some help to it.
// model
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
public DateTime AuditDate { get; set; }
// view
@Html.LabelFor(model => model.AuditDate, htmlAttributes: new { @class = "col-md-2 col-form-label text-md-right" })
@Html.TextBoxFor(model => model.AuditDate, "{0:MM/dd/yyyy}", new { @class = "form-control datepicker" })
@Html.ValidationMessageFor(model => model.AuditDate, "", new { @class = "text-danger" })
Prasad RaveendranPosted Feb 28, 2024, 11:53 PM
Try the below options and see whether this would help
Ensure that your model is valid. If there are any validation errors, it might affect the display format. You can check the model state in your controller action before rendering the view:
Try adjusting the format directly in the
TextBoxFormethod in your view:Instead of
TextBoxFor, you can try usingEditorFor:Guest UserPosted Feb 29, 2024, 6:17 AM
Hi Prasad
Thanks so much, it now display, issue was using TextBoxFor instead of EditorFor.