Asp.Net Core 3.1 with Razor - Grid CRUD example

Hi,

I found some sample code on this forum for EJ2 asp.net core 3.1 with grid.
However I am not able to get my project to work based on the sample. Please see attachment. The relevant code is in /Pages/Employee/Index. Can you please show me how to display the data in my grid.

Also your current control panel App for "Syncfusion ASP.NET Core (EJ2) Control Panel 18.1.0.xx" is with Target Target Framework = .NET Core 2.0.
Do you have a similar app for .Net Core 3.1 with Razor examples instead of  MVC.

Thanks
Avinash Tauro

Attachment: EmployeeListRazor_92012108.zip

6 Replies

AV Avinash May 24, 2020 01:11 AM UTC

Hi,

I figured it out. So the issue in my project was that the OnGet was getting called but OnPostDataSource was not getting called.

Then I noticed that the grid Load event (js function onLoad) had a spelling mistake. I fixed it and now the OnPostDataSource is getting called correctly, and the grid is populated.

I tried to remove the load event handler and the OnPostDataSource is no called.

Please share a link if possible, which explains why this below code is mandatory and why it does a post callback.
<script>
function onLoad() {
        this.dataSource.dataSource.headers = [{ 'XSRF-TOKEN':     $("input:hidden[name='__RequestVerificationToken']").val() }];
    }
</script>

Thanks
Avinash Tauro


RR Rajapandi Ravi Syncfusion Team May 25, 2020 07:29 AM UTC

Hi Avinash, 
 
We are happy to hear that you have founded the solution at your end. 

Query#: why this below code is mandatory and why it does a post callback. 

To use DataManager in ASP.NET Core Razor pages, you need to add AntiForgery tokens in the headers property of the DataManager and set ValidateAntiForgeryToken attribute in the server side method. If you remove the load event , in server side the OnPostDatasource fails in the authentication process. It was the cause of the issue. Please refer the below documentation for more information. 
 

Regards,
Rajapandi R 



AV Avinash May 25, 2020 11:45 AM UTC

Thank you for the information about the anti-forgery tokens.

Also please let me know about my 2nd part of query
--------------
Also your current control panel App for "Syncfusion ASP.NET Core (EJ2) Control Panel 18.1.0.xx" is with Target Target Framework = .NET Core 2.0.
Do you have a similar app for .Net Core 3.1 with Razor examples instead of  MVC.
--------------

Avinash Tauro


TS Thiyagu Subramani Syncfusion Team May 26, 2020 08:01 AM UTC

Hi Avinash, 

Thanks for your update. 

Based on your reported information we have prepared a sample with latest source in .Net Core 3.1 with Razor examples instead of  MVC.  Please refer the below sample. 


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

Regards, 
Thiyagu S. 



AV Avinash May 26, 2020 08:11 AM UTC

Hi,

Thanks for the sample. The code base works fine.
Though in couple of places it is using old code which is not needed for Asp.NET Core 3.1 Razor pages.
For e.g. in attached codebase class CRUDAction<T> is defined in index.cshtml.cs. This is not needed as CRUDModel<T> is already available in Syncfusion.EJ2.Base

Also I will be using many more controls in the coming weeks.
Is there a repository where I can see the demos/sample for all EJ2 controls with Asp.NET Core 3.1 with Razor pages.

Thanks
Avinash Tauro


TS Thiyagu Subramani Syncfusion Team May 27, 2020 11:52 AM UTC

Hi Avinash, 

Thanks for your update. 

Query : Is there a repository where I can see the demos/sample for all EJ2 controls with Asp.NET Core 3.1 with Razor pages  

No, currently there is no repository to refer our demos/samples in ASP.NET core 3.1 with razor pages.  

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

Regards, 
Thiyagu S 


Loader.
Up arrow icon