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:控制器动作参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)
Bind multiple parameters from route and body to a model in ASP.NET Core(在ASP.NET Core中将路由和主体中的多个参数绑定到一个模型)
Custom model binding in AspNet Core WebApi?(AspNet Core WebApi中的自定义模型绑定?)
How to minify in .net core mvc view?(如何在.Net核心MVC视图中缩小?)