Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
752 views
in Technique[技术] by (71.8m points)

asp.net - jqgrid editurl : controller action parameters

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?

Grid code:

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

Add new row code:

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

Controller code:

public ActionResult SaveCustomLanguageData()
{
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...