The Update Handler is not called in .NET 6 project

Hi,

I have created a new Asp.NET 6 project and added ejs-grid with RemoteSaveAdaptor

The data is listing correct however, the Update handler in cs file is not getting called, when I edit a record and save it.

Please find attached project. See GridDemo.cshtml

Thanks

Avinash Tauro


Attachment: SyncfusionDemoDotNet6_2dc0b2f8.zip

3 Replies

RS Rajapandiyan Settu Syncfusion Team February 4, 2022 07:05 AM UTC

Hi Avinash, 
 
Greetings from Syncfusion support. 
 
By analyzing your code, we found that you did not send verification token in the Grid headers. This may cause the reported behavior. 
 
In Razor project, the POST request is used for calling the URL method in the index.cshtml.cs page, so we need to configure ‘XSRF-TOKEN’ in the program.cs page like given below, 
 
 
[program.cs] 
 
builder.Services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN"); 
 
 
Then, add the verification token to the Grid data source’s header property in its load event as explained in the following code snippet, 
 
 
[index.cshtml] 
 
@Html.AntiForgeryToken() 
 
<ejs-grid id="Grid" allowPaging="true" load="onLoad" toolbar="@( new List<object>() {"Edit","Update","Cancel"})"> 
   <e-data-manager json="@Model.Datasource.ToArray()" adaptor="RemoteSaveAdaptor" updateUrl="Index?handler=Update"></e-data-manager> 
   --- 
</ejs-grid> 
 
<script> 
    function onLoad() {    
        this.dataSource.dataSource.headers = [{ 'XSRF-TOKEN': $("input:hidden[name='__RequestVerificationToken']").val() }]; 
    } 
</script> 
 
 
Refer to the below link to know more about anti-forgery-tokens. 
 
 
Please get back to us if you need any assistance. 
 
Regards, 
Rajapandiyan S 



AV Avinash February 7, 2022 08:00 AM UTC

Thanks, it works. I had missed the entry in program.cs



SK Sujith Kumar Rajkumar Syncfusion Team February 8, 2022 05:38 AM UTC

Hi Avinash, 
 
Thanks for the update. We are glad to hear that your query has been resolved. 
 
Regards, 
Sujith R 


Loader.
Up arrow icon