JQGrid能够通过主CRUD控件传递ValidateAntiForgeryToken吗?

这是我第一次设置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不允许我在文档站点上阅读的内容。 有没有人有任何经验通过主网格的CRUD控件? 绝对赞赏任何和所有的帮助!

使用key: true肯定是错误的key: true对于一列来说更key: true 。 它打破了rowid。 行的id值必须在HTML页面上具有唯一值。 我建议你validation你使用的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允许您分析在编辑期间将发送到服务器的数据,并根据数据生成返回的数据。

Interesting Posts