简体   繁体   中英

Serialize() Jquery returns null for fields date type

I'm trying to serialize my form I have values ​​in my PartialViewResult (ASPNET MVC 4) but is coming DATE type fields to null, does anyone know why? Thanks!

$.ajax({
    url: '@Url.Action("CadastroLancamentoParcelar")',
    type: 'GET',
    cache: false,
    context: this,
    data: $("#LancamentoForm").serialize(),
    success: function (result) {
        $(this).html(result);
    },
    close: function (event, ui) {
        $('#dialog-parcelar').empty();
    }
});

My PartialViewResult:

    [Security]
    [HttpGet]
    public PartialViewResult CadastroLancamentoParcelar(LancamentoReceitaDespesa lancamento)
    {
        lancamento.decLancamentoParcelaValor = lancamento.decLancamentoReceitaDespesaValor;

        return PartialView("_CadastroLancamentoParcelar", lancamento);
    }

HTML MVC:

     @Html.TextBoxFor(model => model.dtLancamentoReceitaDespesaDataVencimento, "{0: dd/MM/yyyy}", new { @maxlength = "10", @style = "width:107px;", @onkeypress = "mascara(this,mdata);", autocomplete = "off", @id = "txtCalendario" })

HTML:

 <input autocomplete="off" data-val="true" data-val-date="The field Data do Vencimento: must be a date." id="txtCalendario" maxlength="10" name="dtLancamentoReceitaDespesaDataVencimento" onkeypress="mascara(this,mdata);" style="width:107px;" type="text" value="" class="hasDatepicker">

already solved the problem...

There's a gotcha with the default model binder that is not easy to know about but once you know it you no longer make the same mistake:

When you use a POST request, the default model binder uses your culture settings to parse the dates.

When you use a GET request, the default model binder uses CultureInfo.InvariantCulture to parse the dates and ignores your current culture settings.

follow the link discovery: Passing a DateTime to controller via URL causing error in ASP .NET MVC 3 (culture)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM