Serialize()Jquery为字段日期类型返回null

时间:2013-12-19 13:05:56

标签: jquery asp.net-mvc-4 jsonserializer

我正在尝试序列化我的表单我在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">

1 个答案:

答案 0 :(得分:1)

已经解决了问题...

使用默认型号活页夹并不容易了解但是一旦你知道它就不再犯同样的错误:

使用POST请求时,默认模型绑定器使用您的区域设置来解析日期。

当您使用GET请求时,默认模型绑定器使用CultureInfo.InvariantCulture来解析日期并忽略您当前的文化设置。

按照链接发现: Passing a DateTime to controller via URL causing error in ASP .NET MVC 3 (culture)

相关问题