I have a field in the DataHora database, my class is simple and has no annotation
public DateTime DataHora { get; set; }
I have these two fields on the screen for the user who will use a single field in the DB
<div class="form-group">
@Html.LabelFor(model => model.DataHora, "Liberar às", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DataHora, new { htmlAttributes = new { @class = "form-control TextoTextBox", id="hora", DataFormatString = "{hh:mm}" } })
@Html.ValidationMessageFor(model => model.DataHora, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DataHora, "Liberar dia", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DataHora, new { htmlAttributes = new { @class = "form-control TextoTextBox", id = "data", DataFormatString="{0:dd/MM/yyyy}" } })
@Html.ValidationMessageFor(model => model.DataHora, "", new { @class = "text-danger" })
</div>
</div>
I wanted to know what I need to do so that these two fields on the screen can use a single field of the class and the bank, because when I shoot the focus (I click somewhere else) it displays this error message:
The field DataHora must be a date.
And another thing I noticed is that the date pattern does not allow me to enter the Brazilian format, only the American, but I did the validation using the
DataFormatString="{0: dd / MM / yyyy}"
in EditorFor (at the end of the fields).