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. Image for the cookie policy date

UrlAdaptor and Route Data

i am working on ASP.NET CORE with razor page.

I have a grid with CRUD operation (UrlAdaptor).
I am able to bind data, filter and execute CRUD.

My problem is related to the bind inside OnPostLoadData because i want to filter the datasource with the Route Data parameters.
I am unable to retrieve the Route Data inside OnPostLoadData i think because the ajax request doesn't allow it.
How i can solve it? maybe pass additional parameter on PostLoadData? How?


CSHTML code:
@page "{Route1?}"
@model Test.Pages.Gridmodel_sede_installazione

@using Syncfusion.EJ2;

    <ejs-grid id="grid" dataBound="dataBound" allowFiltering="true" allowSorting="true" allowResizing="true" allowPaging="true"
              showColumnChooser="true" showColumnMenu="true" load="onload" 
              toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update", "Search" })"
        <e-data-manager url="/Grid_sede_installazione?handler=LoadData" insertUrl="/Grid_sede_installazione?handler=Insert" 
            updateUrl="/Grid_sede_installazione?handler=Update" removeUrl="/Grid_sede_installazione?handler=Delete" adaptor="UrlAdaptor"></e-data-manager>
        <e-grid-filterSettings type="Menu"></e-grid-filterSettings>
        <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Dialog"></e-grid-editSettings>
            <e-grid-column field="Column1" headerText="Column1" visible="false" isidentity="true" isPrimaryKey="true" width="120"></e-grid-column>
            <e-grid-column field="Column2" headerText="Column2" validationRules="@(new { required=true})" width="120"></e-grid-column>
            <e-grid-column field="Column3" headerText="Column3" width="120"></e-grid-column>
              @*default value with Route Data? defaultValue="(@RouteData.Values["PartitaIva"].ToString())"*@

    function onLoad(args) {
        this.dataSource.dataSource.headers = [{ 'XSRF-TOKEN': $("input:hidden[name='__RequestVerificationToken']").val() }];

    function dataBound(args) {

CS code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Web;
using Syncfusion.EJ2.Base;
using System.Collections;
using Newtonsoft.Json;
using Microsoft.EntityFrameworkCore;

namespace Test.Pages
    [IgnoreAntiforgeryToken(Order = 1001)] // This is necessary to trigger the method OnPostLoadData and OnPostUpdateData
    public class Gridmodel_sede_installazione : PageModel
        //carico il collegamento al database
        public Context context = new Context (); //EntityFrameworkCore Postgres

        [BindProperty(SupportsGet = true)]        //in alternativa  public void OnGet(string Route1)
        public string Route1{ get; set; }
        public void OnGet() { }

        public JsonResult OnPostLoadData([FromBody] DataManagerRequest dm)
            IEnumerable data;
            if (Route1== null)
                data = context.Anagrafica.ToList();
                data =  context.Anagrafica.Where(s => s.Column6== Route1).ToList();
            //fa tutto in automatico, filtri, ordinamento, restituzione dati, ...
            int count = context.Anagrafica.Count();
            DataOperations operation = new DataOperations();
            data = operation.Execute(data, dm);
            return new JsonResult(new { result = data, count = count }, new JsonSerializerSettings());

        public JsonResult OnPostInsert([FromBody]CRUDModel<Anagrafica> value)
            return new JsonResult(value.Value);

        public JsonResult OnPostUpdateAsync([FromBody]CRUDModel<Anagrafica> value)
            var entity = context.Anagrafica.AsNoTracking().FirstOrDefault(s => s.Column6== value.Value.Column6);
            if (entity != null)

            return new JsonResult(value.Value);

        public JsonResult OnPostDelete([FromBody]CRUDModel<Anagrafica> value)
            var entity = context.Anagrafica.FirstOrDefault(s => s.Column6== value.Key.ToString());
            if (entity != null)
            return new JsonResult(value);


3 Replies

MF Mohammed Farook J Syncfusion Team December 14, 2018 10:40 AM UTC

Hi luigi, 

Thanks for contacting Syncfusion support. 

Query : pass additional parameter on PostLoadData? How? 
We have analyzed your query. We suggest you to refer to the below documentation to pass additional parameters to server. 

Please get back to us if you need further assistance. 
J Mohammed Farook 

LU luigi December 14, 2018 03:09 PM UTC

ok thanks for the reply
very simple. I had not found that item in the documentation.

MF Mohammed Farook J Syncfusion Team December 17, 2018 09:12 AM UTC

Hi luigi,  
Thanks for your update. 
We are happy to hear that the provided solution has been resolved your problem. You can find the help documentation and demo from the following link 
Please get back to us if you need further assistance. 
J Mohammed Farook 

Live Chat Icon For mobile
Up arrow icon