14
I have a field in my application in mvc Asp.net c# to put start date and end date.
[Required(ErrorMessage = "A data de início é obrigatória")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime DataInicio { get; set; }
However, while the user is typing the date appears below the field a message in red:
The field must be a date.
I didn’t implement this, I don’t know where it comes from. Does anyone know how to disappear with this alert?
View
@model Competências.Models.Experiencia
@Scripts.Render("~/bundles/validation")
@using (Ajax.BeginForm(new AjaxOptions
{
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST"
}))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<div class="modal-body row">
<div class="col-md-7">
@Html.LabelFor(model => model.Nome)
@Html.TextBoxFor(model => model.Nome, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Nome)
</div>
<div class="col-md-5">
@Html.LabelFor(model => model.Funcao)
@Html.TextBoxFor(model => model.Funcao, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Funcao)
</div>
</div>
<div class="modal-body row">
<div class="col-md-4">
@Html.LabelFor(model => model.DataInicio)
@Html.EditorFor(model => model.DataInicio, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.DataInicio)
</div>
<div class="col-md-4">
@Html.LabelFor(model => model.DataFinal)
@Html.EditorFor(model => model.DataFinal, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.DataFinal)
</div>
</div>
<div class="modal-footer">
<input class="btn btn-primary" type="submit" value="Salvar" />
<a class="btn btn-default" onclick="FechaModal();">Cancelar</a>
</div>
}
Input generated in the browser
<div class="modal-body row">
<div class="col-md-4">
<b>Data de Início</b>
<input class="text-box single-line" data-val="true" data-val-date="O campo DataInicio deve ser uma data." data-val-required="A data de início é obrigatória" id="DataInicio" name="DataInicio" type="date" value="">
<span class="field-validation-valid" data-valmsg-for="DataInicio" data-valmsg-replace="true"></span>
</div>
<div class="col-md-4">
<b>Data Final</b>
<input class="text-box single-line" data-val="true" data-val-date="O campo DataFinal deve ser uma data." data-val-required="A data de início é obrigatória" id="DataFinal" name="DataFinal" type="datetime" value="">
<span class="field-validation-valid" data-valmsg-for="DataFinal" data-valmsg-replace="true"></span>
</div>
<div class="col-md-3">
</div>
</div>
You installed the
jquery-validate
, theglobalize
and thejquery.globalize
in your project?– Leonel Sanches da Silva
I got the project already started, I can’t tell you. How do I check this? I need to install or uninstall?
– kLucas
I’ll give you a little script.
– Leonel Sanches da Silva
What is the file code
Shared/EditorTemplates/DateTime.cshtml
? What is the HTML generated in your view?<input ... >
– ridermansb
It puts the input code in which you need to declare the date for us to see and your question becomes clearer !
– Érik Thiago