jqgrid editurl:控制器动作参数

jqgrid editurl : controller action parameters(jqgrid editurl:控制器动作参数)

本文介绍了jqgrid editurl:控制器动作参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When I use editurl property in my jqgrid, the controller action gets called after I hit submit button on adding a new row. But how do I get all the grid rows there? Which parameter should I read from my controller action method in order to get the grid data?

网格代码:

$("#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()
{
}

推荐答案

jqGrid 将名称参数发送到控制器,其名称与您在 colModel 的 'name' 属性中定义的名称相同.另外将发送 oper=addid=_empty.因此,您的控制器操作可能如下所示

jqGrid send to the controller named parameters with the name as you defined in the 'name' property of the colModel. Additionally will be send oper=add and id=_empty. So your controller action can look like following

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 响应进行解码

on the client side you should decode the JSON response for example with the following code

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

这篇关于jqgrid editurl:控制器动作参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:jqgrid editurl:控制器动作参数

基础教程推荐