This is a migrated thread and some comments may be shown as answers.

Passing ID and Anti Forgery Token in Hierarchical Grid

2 Answers 412 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jimmy
Top achievements
Rank 1
Iron
Veteran
Jimmy asked on 02 Jul 2019, 02:33 AM

Can someone advice how do I include anti forgery token and parent ID in the hierarchical grid?

 

    <script id="template" type="text/kendo-tmpl">
        @(Html.Kendo().Grid<TransactionRevenue>()
        .Name("Grid_#=ITransactionId#")
        .Columns(columns =>
        {
            columns.Bound(o => o.InvoiceToName).Title("Receive From").Width(450);
            columns.Bound(o => o.Amount).Format("{0:c}").Width(200);
        })
        .DataSource(dataSource => dataSource
            .Ajax()
            .ServerOperation(false)
        .Read(read => read.Action("HierarchyBinding_Orders", "Grid", new { TID = "#=ITransactionId#" }))  //****Need to include token here
        )
        .Sortable()
        .ToClientTemplate()
        )
    </script>

2 Answers, 1 is accepted

Sort by
0
Jimmy
Top achievements
Rank 1
Iron
Veteran
answered on 03 Jul 2019, 09:56 AM

found the solution:

 

        .DataSource(dataSource => dataSource
            .Ajax()
            .ServerOperation(false)
            .Read(r => r.Url("?handler=GetRevenueList").Data("GetTransIDForRevenue(#=ITransactionId#)"))
        )

.

.

.

        function GetTransIDForRevenue(id) {
            var temp = $.extend(true, {}, forgeryToken(), { TID: id });
            return temp;
        }

0
Tsvetomir
Telerik team
answered on 03 Jul 2019, 01:05 PM
Hi Jimmy,

Generally, when additional parameters have to be sent to the server-side with any of the CRUD requests, it is recommended to make use of the Data() property. It accepts a JavaScript function name. In the handler, an object can be returned, therefore, obtain them on the server-side. 

As per the forgery token, the Kendo UI suite exposes a method called antiForgeryTokens and more information could be obtained here:

https://docs.telerik.com/kendo-ui/api/javascript/kendo/methods/antiforgerytokens

Let me know in case additional questions arise.


Kind regards,
Tsvetomir
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Jimmy
Top achievements
Rank 1
Iron
Veteran
Answers by
Jimmy
Top achievements
Rank 1
Iron
Veteran
Tsvetomir
Telerik team
Share this question
or