【问题标题】:Post jqgrid data to mvc3 controller将 jqgrid 数据发布到 mvc3 控制器
【发布时间】:2011-07-21 20:50:47
【问题描述】:

我应该如何将 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,但不是从视图中发送 jquery

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

【问题讨论】:

  • 先显示您的代码,以便我们有一个共同的讨论基础。现在你的问题很笼统。
  • @darin-dimitrov 这是一些代码,谢谢!

标签: asp.net-mvc-3 jqgrid


【解决方案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)); }
});

【讨论】:

    猜你喜欢
    • 2017-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-05
    • 2015-08-02
    • 2014-09-07
    • 2013-10-25
    相关资源
    最近更新 更多