将jqgrid数据发布到mvc3控制器

时间:2011-07-21 20:50:47

标签: asp.net-mvc-3 jqgrid

我应该如何将在jqgrid插件中输入的数据发布到MVC3控制器?

提前致谢

一些代码

将数据发送到mvc3控制器

        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"
        });

控制器

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Nueva(FacturaNuevaModel model)
    {
        return Json(model);
    }

模型

public class FacturaNuevaModel
{
    public string ObraSocialId { get; set; }
    public IList<Linea> Lineas { get; set; }

我不能理解的是,我发送的海报和作品相同的Json,但不是视图中的whit jquery

使用视图中的帖子,ObraSocialId填充在控制器中,Lineas集合包含项目,但Linea中的每个属性都具有空值

1 个答案:

答案 0 :(得分:1)

问题是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)); }
});
相关问题