I'm doing a filter for a paged list. The values of this filter must be sent via ajax with verb GET.
This is the model:
public class FiltroViewModel
{
public DateTime? CriadosDe { get;set; }
public DateTime? CriadosAte { get;set; }
}
This is the view: (I do not know if it makes a difference, but I use bootstrap-datepicker's eternicode)
<form class="form-horizontal" data-form-filter>
<div class="form-group">
<div class="col-sm-6">
<div class="input-daterange input-group" id="datepicker">
@Html.TextBoxFor(m => m.CriadosDe, "{0:d}", new { @class = "input-sm form-control" })
<span class="input-group-addon">Até</span>
@Html.TextBoxFor(m => m.CriadosAte, "{0:d}", new { @class = "input-sm form-control" })
</div>
</div>
</div>
Jquery
var formData = $(document).find('[data-form-filter]').serialize();
$.ajax({
type: "GET",
url: url,
dataType: "json",
data: formData,
success: function (data) {
fazAlgo();
},
});
Assuming a Created = 04/10/2016 and a CreatedAtly = 10/28/2016, the serialization looks like this:
&CriadosDe=04%2F10%2F2016&CriadosAte=28%2F10%2F2016
The problem is that the model arrives with these values in the controller:
CriadosDe = 10/04/2016
CriadosAte = null
That is, the server attempted to interpret as mm / dd / yyyy. How to make it always interpret as dd / mm / yyyy?