-1
I’m in a strange situation.
I am working with datepicker jquery, asp net mvc 5.
i configured the datepicker for the format as below:
$(".datepicker").datepicker({
autoclose: true,
buttonImageOnly: true,
showAnim: 'slideDown',
duration: 'fast',
buttonText: "Calendário",
dateFormat: 'dd/mm/yy',
showOn: "both",
buttonImage: "../Content/images/calendario.png",
clearBtn: true,
dayNames: ['Domingo', 'Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado', 'Domingo'],
dayNamesMin: ['D', 'S', 'T', 'Q', 'Q', 'S', 'S', 'D'],
dayNamesShort: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb', 'Dom'],
monthNames: ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'],
monthNamesShort: ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'],
onSelect: function () {
$(this).removeClass('input-validation-error');
$('#dataDeInicio-error').hide();
}
});
It comes from a multiselect:
@Html.TextBoxFor(model => model.DataDeInicioDaQuestao, "{0:dd/MM/yyyy}", new { @Value = Model.DataDeInicioDaQuestao.HasValue ? Model.DataDeInicioDaQuestao.Value.ToString("dd/MM/yyyy") : String.Empty, @class = "datepicker campoData grid_2", @id = "DataDeInicioDaQuestao", maxlength = "10", @readonly = "readonly" })
But when I give Ubmit in the form it sends to Actionresult the date in wrong format. So, for example, if I put the date 18/07/2019 it considers 07/18/2019 and the error occurs.
public ActionResult ObterRelatorioDeRelatorioDePercentualDeAcertosDaQuestao(DateTime? dataDeInicioDaQuestao, DateTime? dataDeFimDaQuestao, string questao)
{
try
{}
}
what I do????
first change your parameters of
DateTime?
forstring
and see the format that is coming up. Dai can easily format in C#– Ricardo Pontual
as I didn’t think of it, right? It worked now. Then it was just convert the string to date. Thank you so much!
– Rafaela Marraschi
good, dates are always a problem.. another solution would be to use the library Moment.js and convert the format in javascript, have some examples here on the site, works well
– Ricardo Pontual