Looking for sample code on how to do batch operation with anti-forgery-token

Hello,

I'm looking for some sample code to the exact thing as the following link, but with batch operations and not just single crud operations.

https://ej2.syncfusion.com/aspnetcore/documentation/grid/how-to/perform-crud-operation-using-anti-forgery-token/?no-cache=1

I'm not sure where to start.

Cheers,

Warren

1 Reply 1 reply marked as answer

TS Thiyagu Subramani Syncfusion Team June 2, 2021 01:28 AM UTC

Hi Warren, 

Thanks for contacting Syncfusion support. 

Based on your shared information we suspect that you want to send anti-forgery-token for batch Operations. For this we suggest you to use below code in batchRequest in customAdaptor. Please refer to the below code and screenshot for more reference. 

<ejs-grid id="Grid"  toolbar="@(new List<string>() { "Add","Delete","Update", "Cancel" })" allowPaging="true"> 
        <e-data-manager json="@ViewBag.DataSource.ToArray()" adaptor="RemoteSaveAdaptor" batchUrl="/Home/BatchUpdate"></e-data-manager> 
        <e-grid-editSettings allowDeleting="true" allowEditing="true" allowAdding="true" mode="Batch"></e-grid-editSettings> 
        <e-grid-pagesettings pageCount="5"></e-grid-pagesettings> 
        <e-grid-columns> 
            <e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" validationRules="@(new { required=true})" textAlign="Right" width="120"></e-grid-column> 
. . . . . . . . . . .  
        </e-grid-columns> 
    </ejs-grid> 
<script> 
    document.addEventListener('DOMContentLoaded', function () { 
        window.customAdaptor = new ej.data.RemoteSaveAdaptor(); 
        var gridObj = document.getElementsByClassName('e-grid')[0].ej2_instances[0]; 
        gridObj.dataSource.adaptor = customAdaptor; 
        customAdaptor = ej.base.extend(customAdaptor, { 
            batchRequest: function (dm, changes, e, query, original) { 
                return { 
                    type: 'POST', 
                    url: dm.dataSource.batchUrl || dm.dataSource.crudUrl || dm.dataSource.url, 
                    contentType: 'application/json; charset=utf-8', 
                    dataType: 'json', 
                    data: JSON.stringify({ 
                        changed: changes.changedRecords, 
                        added: changes.addedRecords, 
                        deleted: changes.deletedRecords, 
                        __RequestVerificationToken: document.getElementsByName("__RequestVerificationToken")[0].value, 
                        action: 'batch', 
                        table: e.url, 
                        key: e.key 
                    }) 
                } 
            } 
        }); 
    }); 
</script> 
  
 


Please get back to us, if you need any further assistance. 

Regards, 
Thiyagu S 


Marked as answer
Loader.
Up arrow icon