We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Grid using ASP .NET Core 2 with Razor Pages

Thread ID:





132734 Sep 18,2017 10:12 PM UTC Jan 25,2018 04:07 PM UTC ASP.NET Core 11
Tags: Grid
Valer Bocan
Asked On September 18, 2017 10:12 PM UTC


Could you please a working sample of the grid control in an ASP .NET Core 2 app using the new Razor page functionality?

I tried hacking my way through Razor pages, to no avail. For instance, I have the following grid declaration:

<e-datamanager json="(IEnumerable<object>)ViewBag.datasource" insert-url="/Clients/InsertClient" adaptor="remoteSaveAdaptor" />

In the Clients code-behind file, I have the following method:

public void OnPostInsertClient()

The method does not get called and in the browser developer tools I see:

   Request URL: http://localhost:51315/Clients/InsertClient
   Request Method: POST
   Status Code: 404 / Not Found

What am I doing wrong?

Saravanan Arunachalam [Syncfusion]
Replied On September 19, 2017 09:16 AM UTC

Hi Valer, 
Thanks for contacting Syncfusion’s support. 
Query 1: Could you please a working sample of the grid control in an ASP .NET Core 2 app using the new Razor page functionality? 
We have analyzed your query and we have already discussed this query in the following UG document and online demo that can be refer from the below links. 
And also we have created a sample based on your requirement that can be refer from the below link. 
Query 2: What I am doing wrong? 
We have analyzed your provided code, the reported issue could be possibly occur due to the requested is not found on the server side. So, we suspect that you have specified “/Clients/InsertClient” in the insert-url of dataManager that the method was not defined on the server which was the cause of the issue. 
So, please ensure the action name in the Url and defined action name on server will be same to avoid your reported issue. 
Saravanan A.   

Steven Olensky
Replied On October 2, 2017 11:03 PM UTC

I am having the same problem.

I think you guys at Synfusion missed the fact that this is "Razor Pages" in Core 2.0. Razor Pages support multiple "Handlers". Please look at: https://docs.microsoft.com/en-us/aspnet/core/mvc/razor-pages/?tabs=visual-studio#customizing-routing

For some reason, the post method on the Razor Page never gets called.

Saravanan Arunachalam [Syncfusion]
Replied On October 3, 2017 02:29 PM UTC

Hi Steven, 
We have analyzed your provided link, the Razor page handler is called by the form post which make the full post back with server and the DataManager called the handler by the ajax post back which make the partial post back with server. So, our DataManager is entirely different from the Razor page handler. 
Saravanan A. 

R Brian Lindahl
Replied On October 5, 2017 05:13 PM UTC

The problem is probably due to the fact that razor pages automatically check for the RequestVerificationToken, assuming a form-driven post. I found it necessary to do the following:

1. Add a property & constructor to the pagemodel to receive the anti-forgery injection:

    public IAntiforgery Xsrf { get; private set; }

    public MyPageModel(IAntiforgery xsrf)
      Xsrf = xsrf;

2. Declare a property on the pages' codebehind:

    public List> Headers
        var hdr = new List>();
        var dict = new Dictionary
          ["RequestVerificationToken"] = Xsrf.GetAndStoreTokens(HttpContext).RequestToken
        return hdr;

3. In the datamanager tag helper, add a "headers" attribute:

                           headers=@Model.Headers />

This will send the token as part of the header to any of the CRUD requests, and you should see the handlers firing.

Also, make sure you have

@page "{handler?}"

at the top of your cshtml so that it knows to route the extra handlers. (see the link that Steven posted for more info)

Saravanan Arunachalam [Syncfusion]
Replied On October 6, 2017 10:03 AM UTC

Hi Brian, 
The support incident has been created under your account for your reported query. Please log on to our support website to check for further updates. 
Saravanan A. 

stephane pasin
Replied On January 18, 2018 09:08 AM UTC

in the same idea,
Do you have a working sample for asp.net core razor pages ?

That is to say without MVC nor file controler ...

only .cshtml and .cshtml.cs pages.

I think it's possible but I can not configure it

Renjith Singh Rajendran [Syncfusion]
Replied On January 19, 2018 03:33 PM UTC

Hi Stephane,  
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. Make sure that you have defined the route in your view: @page “{handler?}”. Refer to the below code.  
@page "{handler?}"  
@model IndexModel  
<ej-grid id="FlatGrid" query="new ej.Query()">  
    <e-datamanager url="DataSource" adaptor="UrlAdaptor" headers='new List<Dictionary<string,object>> { new Dictionary<string, object>() { { "XSRF-TOKEN", "YOUR ANTI FORGERY TOKEN HERE" } } }'></e-datamanager>  
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .   
public ActionResult OnPostDataSource()  
. . . . . . . . . . . . . . . . . . . . . . . . . .   
Renjith Singh Rajendran. 

stephane pasin
Replied On January 19, 2018 11:39 PM UTC

Hello, Thank you for you answer 
If i use your sample i dont have data into the grid 

the same in my projet

with the same datasource a table have row but not the grid

Replied On January 21, 2018 12:53 PM UTC

Hi Brian, 
The support incident has been created under your account for your reported query. Please log on to our support website to check for further updates. 
Saravanan A. 

i like it and i want it

stephane pasin
Replied On January 21, 2018 09:28 PM UTC


I too hope we will have an answer on Monday 

For synfusion support 

I want to limit the number of row par page to 6 row. 

How should I write it with Razor

have a nice day

Farveen Sulthana Thameeztheen Basha [Syncfusion]
Replied On January 25, 2018 04:07 PM UTC

Hi Stephane, 

We have checked your query and  further analyzing your screenshots you have used remoteSaveAdaptor on Razor pages so that we have prepared sample using remoteSaveAdaptor and return the data using model. 
Please ensure in your sample project you have resolved camel casing problem i.e  make first Letter of the FieldName in capital (ex:- OrderID, CustomerID).   

Please refer to the link:- 

Please refer to the code example:- 

<div style="padding:20px;"> 
    <ej-grid id="FlatGrid" allow-paging="true"> 
        <e-datamanager json="@Model.TestModel.Orderdata" update-url="NormalUpdate" insert-url="NormalInsert" remove-url="NormalDelete" adaptor="remoteSaveAdaptor" /> 
            <e-column field="OrderID" header-text="Order ID" is-primary-key="true"  text-align="Right" width="75"></e-column> 
            <e-column field="CustomerID" header-text="Customer ID" width="80"></e-column> 
            .   .    . 
public class IndexModel : PageModel 
        public TestModel TestModel { get; set; } 
        public void OnGet(){ 
        public IActionResult OnPost(TestModel value){ 
            .  .    . 
        public void GetDataSource(){ 
                TestModel.Orderdata.Add(new Order(code + 1, "ALFKI", i + 0, 2.3 * i, new DateTime(1991, 05, 15), "Berlin")); 
                TestModel.Orderdata.Add(new Order(code + 2, "ANATR", i + 2, 3.3 * i, new DateTime(1990, 04, 04), "Madrid")); 
   public class Order 
        public Order() 
        .        .   . 

Please refer to the sample:- 

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


Farveen sulthana T 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon