0

我正在尝试从 mvc3 视图发帖,但我的控制器无法正常工作,但是当我从海报发帖时,相同的 json 工作正常

这是jquery代码

        var lineas = $("#articulosIngresadosTable").getRowData();
        var model = {
            ObraSocialId: $("#idObraSocialTextBox").val(),
            Lineas: lineas
        };

        $.ajax({
            type: 'POST',
            url: '@Url.Action("Nueva", "Factura")',
            data: model,
            success: function (data) { alert(JSON.stringify(data)); },
            dataType: "json"
        });

我仔细检查,模型 var 的 json 与我在 Poster 中使用的相同

这是json:

{"ObraSocialId":"1","Lineas":[{"codigo":"1000","Descripcion":"Articulo 1000","cantidad":"1","importe":"0","descuento":"0","importeDescuento":"0","obrasocial":"","id":"1"},{"codigo":"2000","Descripcion":"Articulo 2000","cantidad":"1","importe":"0","descuento":"0","importeDescuento":"0","obrasocial":"","id":"2"}]}

提前致谢!

4

1 回答 1

0

问题是 contentType ...

var lineas = $("#articulosIngresadosTable").getRowData();
var model = {
    ObraSocialId: $("#idObraSocialTextBox").val(),
    Lineas: lineas
};

var modelString = JSON.stringify(model);

$.ajax({
    type: 'POST',
    url: '@Url.Action("Nueva", "Factura")',
    data: modelString,
    dataType: "json",
    contentType: "application/json; charset=utf-8",
    success: function (data) { alert(JSON.stringify(data)); }
});
于 2011-07-23T12:08:04.253 回答