2
I am making a filter for a paged list. The values of this filter should 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 don’t know if it makes a difference, but I always use bootstrap-datepicker)
<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 Creator = 10/04/2016 and a Creator = 10/28/2016, the serialization is 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 tried to interpret as mm/dd/yyyy. How to make it always interpret as dd/mm/yyyy?
Ever tried to change the
DateTime
forString
?– Marconi
Putz, great idea, I hadn’t thought about it yet! Leave as string already solves everything, even. Thank you. Anyway, let’s see if an answer comes up to use Datetime.
– Eduardo Moreira
I asked a question, see: http://answall.com/questions/156655/varchar-ou-datetime?noredirect=1#comment323008_156655
– Marconi