我已经创建了我的网格,并希望使用网格的默认行为来删除一行.
I have created my grid and would like to use default behaviour of the grid to delete a row.
这是我的网格设置代码:
This is my grid setup code:
$("#grid").jqGrid('navGrid', '#grid_pager',
{ add: true, addtitle: 'Add Customer',
edit: true, edittitle: 'Edit Customer',
del: true, deltitle: 'Delete Customer',
refresh: true, refreshtitle: 'Refresh data',
search: true, searchtitle: 'Advanced search filters',
addfunc: addReferent, editfunc: editReferent
},
{}, // default settings for edit
{}, // default settings for add
{ // define settings for Delete
mtype: "post",
reloadAfterSubmit: true,
url: wsBaseUrl + 'CustomerService.asmx/DeleteCustomer',
resize: false,
serializeDelData: function(postdata) {
return JSON.stringify({ customerID: postdata.id });
}
},
{ // define settings for search
closeOnEscape: true, multipleSearch: true, closeAfterSearch: true
},
{}
);
这是在服务器上定义的网络服务方法
and this is the web service method defined on the server
[WebMethod]
public OperationResult Deletecustomer(string customerID)
{
}
但不幸的是,当我单击删除按钮并在确认窗口上单击确定时,我收到一条错误消息 404.如下图所示
but unfortunately when I click the delete button and click ok on the confirm window I get an error saying 404. as in the following picture
我做错了什么?
我已将以下代码添加到我的 jqGrid 初始化中
I have added the following code to my jqGrid Initialization
// Set defaults value for jqGrid
$.jgrid.defaults = $.extend($.jgrid.defaults, {
mtype: 'post',
datatype: 'json',
jsonReader: {
root: "d.Rows",
page: "d.Page",
total: "d.Total",
records: "d.Records",
repeatitems: false,
userdata: "d.UserData",
id: "Id"
},
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
serializeGridData: function (postData) {
return JSON.stringify(postData);
},
ajaxDelOptions: { contentType: 'application/json; charset=utf-8' },
serializeDelData: function (postData) {
return JSON.stringify(postData);
},
loadui: "block",
multiboxonly: true,
rowNum: 25,
rowList: [25, 50, 100],
altRows: true,
altclass: 'ui-priority-secondary',
autoencode: true,
autowidth: true,
rownumbers: true,
rownumWidth: 30,
gridview: true,
hoverrows: true,
viewrecords: true
});
但我仍然遇到同样的错误...
but I still get the same error...
也许你应该只使用 JSON.stringify
(来自 json2.js) 在 serializeDelData
内.您没有发布您需要删除的网络方法 DeleteCustomer
的原型,但您的问题可能可以通过以下代码解决:
Probably you should just use JSON.stringify
(from json2.js) inside of serializeDelData
. You don't posted the prototype of your web method DeleteCustomer
which you need to delete, but probably your problem could be fixed with the following code:
serializeDelData: function(postdata) {
return JSON.stringify({customerID: postdata.id});
}
使用 ASMX 服务时的另一个常见问题.可能需要定义调用的 Web 方法的所有参数(参见 这里一个例子).
One more common problem in case of the usage of ASMX services. It can be need to define all parameters of the web method called (see here an example).
ajaxDelOptions: { contentType: "application/json" }
参数的用法也大多是必需的.
The usage of ajaxDelOptions: { contentType: "application/json" }
parameter is also required mostly.
使用 Fiddler 或 Firebug 来捕获和分析 HTTP 流量.
It can be helpful to use Fiddler or Firebug to capture and analyse the HTTP traffic.
这篇关于jqGrid 删除一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!