JQGrid 能够通过主要的 CRUD 控件传递 ValidateAntiForgeryToken 吗?
JQGrid able to pass ValidateAntiForgeryToken through the main CRUD controls?
这是我第一次设置 jqGrid,所以我实现了一个基本网格,但是我很难将 __RequestVerificationToken 传递给我的控制器。
$("#RawMatGrid").jqGrid({
url: "/RawMat/GetRawMats",
datatype: 'JSON',
mtype: 'GET',
colNames: [
'Item',
'Product',
'Description'
],
colModel: [
{ name: 'Item', key: true, index: 'Item', sortable: true, editable: true },
{ name: 'Product', key: true, index: 'Product', sortable: true, editable: true },
{ name: 'Description', key: true, index: 'Description', sortable: true, editable: true }
],
pager: "#paging",
rowNum: 10,
rowList: [10, 20, 30, 40, 50],
width: 780,
height: 500,
viewrecords: true,
caption: 'Raw Mats',
emptyrecords: 'No records to display',
autowidth: true,
multiselect: false,
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeateditems: false,
Id: "0"
}
}).navGrid(
"#paging", {
edit: true,
add: true,
del: false,
search: true,
refresh: true
},
{ },
{ //Add
zIndex: 100,
url: '/RawMat/Create',
mtype: 'POST',
// This did not work
editData: { __RequestVerificationToken: jQuery('input[name=__RequestVerificationToken]').val() },
processData: "Processing...",
width: 400,
closeOnEscape: true,
closeAfterEdit: true
},
{});
在尝试使用editData字段失败惨重后,特来请教高手
我看到有人能够通过内嵌的 extraparams 传递令牌的示例,但是 navGrid Add 不允许我在文档站点上阅读的内容中的 extraparams。有没有人有通过主网格的 CRUD 控件传递它的经验?非常感谢任何帮助!
将key: true
用于 more 作为一列绝对是错误的。它打破了rowid。行的 id 值必须在 HTML 页面上具有唯一值。我建议您验证您使用的 jsonReader
是否真的与您使用的输入数据相对应。看起来很可疑。如果您包含 1-2 行输入数据,我可以帮助您更正 jsonReader
.
要发送 __RequestVerificationToken
你应该将它定义为函数:
editData: { __RequestVerificationToken: function () {
return $("input[name=__RequestVerificationToken]").val();
}
或者您可以使用表单编辑的onclickSubmit
回调来扩展数据:只需将editData
替换为
onclickSubmit: function (options, postdata, frmoper) {
return {
__RequestVerificationToken: $("input[name=__RequestVerificationToken]").val();
}
}
我包含了onclickSubmit
回调未使用的参数只是为了表明onclickSubmit
允许您分析将在编辑期间发送到服务器的数据并根据数据生成返回的数据.
这是我第一次设置 jqGrid,所以我实现了一个基本网格,但是我很难将 __RequestVerificationToken 传递给我的控制器。
$("#RawMatGrid").jqGrid({
url: "/RawMat/GetRawMats",
datatype: 'JSON',
mtype: 'GET',
colNames: [
'Item',
'Product',
'Description'
],
colModel: [
{ name: 'Item', key: true, index: 'Item', sortable: true, editable: true },
{ name: 'Product', key: true, index: 'Product', sortable: true, editable: true },
{ name: 'Description', key: true, index: 'Description', sortable: true, editable: true }
],
pager: "#paging",
rowNum: 10,
rowList: [10, 20, 30, 40, 50],
width: 780,
height: 500,
viewrecords: true,
caption: 'Raw Mats',
emptyrecords: 'No records to display',
autowidth: true,
multiselect: false,
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeateditems: false,
Id: "0"
}
}).navGrid(
"#paging", {
edit: true,
add: true,
del: false,
search: true,
refresh: true
},
{ },
{ //Add
zIndex: 100,
url: '/RawMat/Create',
mtype: 'POST',
// This did not work
editData: { __RequestVerificationToken: jQuery('input[name=__RequestVerificationToken]').val() },
processData: "Processing...",
width: 400,
closeOnEscape: true,
closeAfterEdit: true
},
{});
在尝试使用editData字段失败惨重后,特来请教高手
我看到有人能够通过内嵌的 extraparams 传递令牌的示例,但是 navGrid Add 不允许我在文档站点上阅读的内容中的 extraparams。有没有人有通过主网格的 CRUD 控件传递它的经验?非常感谢任何帮助!
将key: true
用于 more 作为一列绝对是错误的。它打破了rowid。行的 id 值必须在 HTML 页面上具有唯一值。我建议您验证您使用的 jsonReader
是否真的与您使用的输入数据相对应。看起来很可疑。如果您包含 1-2 行输入数据,我可以帮助您更正 jsonReader
.
要发送 __RequestVerificationToken
你应该将它定义为函数:
editData: { __RequestVerificationToken: function () {
return $("input[name=__RequestVerificationToken]").val();
}
或者您可以使用表单编辑的onclickSubmit
回调来扩展数据:只需将editData
替换为
onclickSubmit: function (options, postdata, frmoper) {
return {
__RequestVerificationToken: $("input[name=__RequestVerificationToken]").val();
}
}
我包含了onclickSubmit
回调未使用的参数只是为了表明onclickSubmit
允许您分析将在编辑期间发送到服务器的数据并根据数据生成返回的数据.