1
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 BD
<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 elsewhere) it displays this error message:
The field Datahora must be a date.
and another thing I noticed is that the standard date, does not allow me to insert 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).
Hey Fabio, I had a problem, I made a small tutorial: https://answall.com/a/227756/54019
– Matheus Miranda