【问题标题】:jqgrid editurl : controller action parametersjqgrid editurl:控制器动作参数
【发布时间】:2010-11-02 10:35:50
【问题描述】:

当我在我的 jqgrid 中使用 editurl 属性时,控制器操作在我点击提交按钮添加新行后被调用。但是我怎样才能得到所有的网格行呢?为了获取网格数据,我应该从控制器操作方法中读取哪个参数?

网格代码:

$("#list1").jqGrid({
            url: '/CMS/GetCustomLanguageData',
---
---                
editurl: '/CMS/SaveCustomLanguageData'
---

添加新行代码:

grid.jqGrid('editGridRow',"new",{height:280,reloadAfterSubmit:false,addCaption: "Add Record",
    editCaption: "Edit Record",
    bSubmit: "Submit",
    bCancel: "Cancel",
    bClose: "Close",
    saveData: "Data has been changed! Save changes?",
    bYes : "Yes",
    bNo : "No"
});

控制器代码:

public ActionResult SaveCustomLanguageData()
{
}

【问题讨论】:

  • 您能否在问题中包含列定义(colModel),这样我的答案可能会更清楚。您使用哪种类型的 id(int 或 string)?

标签: asp.net jquery jqgrid


【解决方案1】:

jqGrid 将名称参数发送到控制器,其名称与您在colModel 的“名称”属性中定义的名称相同。另外将发送oper=addid=_empty。所以你的控制器动作可能如下所示

public JsonResult SaveCustomLanguageData (string id, string oper, MyObject item)
{
    // test id for "_empty" or oper for "add".
    // If so add the item and return the value of the new id
    // for example return Json ("123");
}

在客户端,您应该使用以下代码对 JSON 响应进行解码

jQuery.extend(jQuery.jgrid.edit, {
    afterSubmit: function (response, postdata) {
        return [true, "", jQuery.parseJSON(response.responseText)];
    }
});

【讨论】:

    猜你喜欢
    • 2011-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-22
    • 2013-05-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多