JQGrid能够通过主CRUD控件传递ValidateAntiForgeryToken吗? [英] JQGrid able to pass ValidateAntiForgeryToken through the main CRUD controls?

查看:112
本文介绍了JQGrid能够通过主CRUD控件传递ValidateAntiForgeryToken吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次设置jqGrid,所以我实现了一个基本的网格,但我很难将__RequestVerificationToken传递给我的控制器。

This is my first time setting up a jqGrid, so I implemented a basic grid but am having a rather difficult time passing the __RequestVerificationToken to my controller.

$("#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字段和失败可怕的情况下,我来问专家。

After trying to use the editData field and failing horribly, I have come to ask the experts.

我看到一个例子,有人能够通过内联中的extraparams传递令牌,但是navGrid Add不允许我在文档站点上阅读的内容。有没有人有任何经验通过主网格的CRUD控件?绝对赞赏任何和所有的帮助!

I saw an example of someone being able to pass the token via extraparams within their inline, but the navGrid Add does not allow extraparams from what I read on the documentation site. Has anyone had any experience passing it through the main grid's CRUD controls? Any and all help is definitely appreciated!

推荐答案

使用键明确错误:true 更多作为一列。它打破了rowid。行的id值必须在HTML页面上具有唯一值。我建议你验证你使用的 jsonReader 是否真正对应你使用的输入数据。看起来很可疑。如果您包含1-2行输入数据,我可以帮助您更正 jsonReader

It's definitively wrong to use key: true for more as one column. It break rowids. The id values of rows must have unique value over the HTML page. I recommend you to verify whether jsonReader which you use really corresponds the input data which you use. It looks suspected. If you includes 1-2 rows of input data I could help you to correct jsonReader.

发送 __ RequestVerificationToken 你应该将它定义为函数:

To send __RequestVerificationToken you should define it as function:

editData: { __RequestVerificationToken: function () {
    return $("input[name=__RequestVerificationToken]").val();
}

或者你可以使用 onclickSubmit 回调表单编辑以扩展数据:只需将 editData 替换为

Alternatively you can use onclickSubmit callback of form editing to extend the data: just replace editData to

onclickSubmit: function (options, postdata, frmoper) {
    return {
        __RequestVerificationToken: $("input[name=__RequestVerificationToken]").val();
    }
}

我包含的未使用参数onclickSubmit 回调仅显示 onclickSubmit 允许您分析在编辑期间将发送到服务器的数据并生成基于的返回数据数据。

I included unused parameters of onclickSubmit callback only to show that onclickSubmit allows you to analyse the data which will be sent to the server during editing and to generate the returned data based on the data.

这篇关于JQGrid能够通过主CRUD控件传递ValidateAntiForgeryToken吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆