繁体   English   中英

Serialize()jQuery对于字段日期类型返回null

[英]Serialize() Jquery returns null for fields date type

我正在尝试序列化我在PartialViewResult(ASPNET MVC 4)中有值的表单,但是DATE类型字段将变为null,有人知道为什么吗? 谢谢!

$.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();
    }
});

我的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">

已经解决了这个问题...

有一个默认模型联编程序的陷阱不容易知道,但是一旦知道就不会再犯同样的错误:

当您使用POST请求时,默认模型联编程序将使用您的区域性设置来解析日期。

当您使用GET请求时,默认模型联编程序将使用CultureInfo.InvariantCulture来解析日期,并忽略当前的区域性设置。

按照链接发现进行操作: 通过URL将DateTime传递给控制器​​,导致ASP .NET MVC 3中的错误(区域性)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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