这是我第一次设置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
允许您分析在编辑期间将发送到服务器的数据,并根据数据生成返回的数据。
需要了解更多jQuery教程分享JQGrid能够通过主CRUD控件传递ValidateAntiForgeryToken吗?,都可以关注jQuery技术分享栏目—计算机技术网(www.ctvol.com)!
以上就是jQuery教程分享JQGrid能够通过主CRUD控件传递ValidateAntiForgeryToken吗?相关内容,想了解更多jQuery开发(异常处理)及jQuery教程关注计算机技术网(www.ctvol.com)!)。
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/jquerytutorial/982813.html