0
I have in my application a search form using Ajaxbeginform. In the same I own a data field (Datetime), and in which I am using the bootstrap datepicker.
My form looks like this:
@using (Ajax.BeginForm("Index", "Pedido", new AjaxOptions { HttpMethod = "Get", InsertionMode = InsertionMode.Replace, UpdateTargetId = "divPedidos" }, new { @class = "form-inline" }))
{
@Html.TextBox("pesquisarRascunhoId", 0, new { style = "display: none" })
<div class="row">
<div class="col-sm-4">
<p>Data emissão</p>
<div class="input-group date col-sm-5">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
@Html.EditorFor(model => model.PedidoFilter.EmissaoInicial, new { htmlAttributes = new { @class = "form-control input-sm datepicker" } })
</div>
a
<div class="input-group date col-sm-5">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
@Html.EditorFor(model => model.PedidoFilter.EmissaoFinal, new { htmlAttributes = new { @class = "form-control input-sm datepicker" } })
</div>
</div>
<div class="btn-search">
<p class="demo-button">
<button type="submit" class="btn btn-success"><i class="fa fa-search"></i><span>Pesquisar</span></button>
</p>
</div>
}
My Java to format my date in dd/mm/yyyy looks like this:
$(".datepicker").datepicker({
format: "dd/mm/yyyy",
language: "pt-BR",
autoclose: true
});
My entity is like this:
public class PedidoFilter
{
public DateTime? EmissaoInicial { get; set; }
public DateTime? EmissaoFinal { get; set; }
}
And finally my controller is like this:
public ActionResult Index(PedidoResult pedidoResult,
{
var pedido = _service.FindAll(pedidoResult.PedidoFilter);
return View(pedido);
}
1 - All fields of my form arrive in my controller, but my date fields are always null, in format dd/mm/yyyy, defining in my datepicker js.
2 - If I enter a date in mm/dd/yyyy format it is passed to my controller.
My question is:
How can I pass my date field in dd/mm/yyyy format and receive them in my controller, without them being null?
You just need to change the application culture. You are using Owin or the settings are in the global.asax?
– Jéf Bueno
I’m not using Owin. I define my culture in my web config: <globalization uiCulture="en" Culture="en-BR" enableClientBasedCulture="true" />
– Mik3i4a5