Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date does not display from Model on HTML input type date

Tags:

People also ask

How do I display a date field in HTML?

<input type="date"> <input> elements of type="date" create input fields that let the user enter a date, either with a textbox that validates the input or a special date picker interface. The resulting value includes the year, month, and day, but not the time.

How do I fix the date format in HTML?

4-on the second function you can use any format you want instead of day+" / "+month+" / "+year for example year+" / "+month+" / "+day and in the text input use a placeholder or value as yyyy / mm / dd for the user when the page load.

How do I display the date format in input?

To set and get the input type date in dd-mm-yyyy format we will use <input> type attribute. The <input> type attribute is used to define a date picker or control field. In this attribute, you can set the range from which day-month-year to which day-month-year date can be selected from.

How can get current date in textbox in HTML?

getDate(); var month = todaydate. getMonth() + 1; var year = todaydate. getFullYear(); var datestring = day + "/" + month + "/" + year; document. getElementById("frmDate").


I am trying to display a date type input on my create and edit Razor Views... The date picker works fine but when editing I do get the value from the Model but the date picker does not display it...

View

<div class="form-group form-md-line-input">
    @Html.TextBoxFor(model => model.InitialDate, new { @class = "form-control", type = "date" })
    @Html.ValidationMessageFor(model => model.InitialDate)
    @Html.LabelFor(model => model.InitialDate)
</div>

Model

public Nullable<System.DateTime> InitialDate { get; set; }

I have tried using the DataAnnotations but the same thing happens the date picker only allows me to select the date on the create but when editing it does not display the date from the model although when I looked at the HTML Code that is rendered, the value for the date is being set but the control does not display it.

HTML View

<input class="form-control" data-val="true" data-val-date="The field InitialDate must be a date." id="InitialDate" name="InitialDate" type="date" value="3/3/2015 12:00:00 AM">

I also removed the time from attribute value from the browser's developers tools to see if it works, but it didn't work either...

<input class="form-control" data-val="true" data-val-date="The field InitialDate must be a date." id="InitialDate" name="InitialDate" type="date" value="3/3/2015">

How can I Display the Date from the Model in the date picker? Any help will be appreciated...