Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 473.7k

How to create datetime on asp.net mvc framework?

Feb 28 2024 7:06 PM

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

<div class="form-group row">
                            @Html.LabelFor(model => model.AuditDate, htmlAttributes: new { @class = "col-md-2 col-form-label text-md-right" })
                            <div class="col-md-10">
                                @Html.TextBoxFor(model => model.AuditDate, "{0:MM/dd/yyyy}", new { @class = "form-control datepicker" })
                                @Html.ValidationMessageFor(model => model.AuditDate, "", new { @class = "text-danger" })
                            </div>
                        </div>

 


Answers (2)