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

UrlAdaptor and Route Data

Thread ID:

Created:

Updated:

Platform:

Replies:

141476 Dec 13,2018 09:50 AM UTC Dec 17,2018 09:12 AM UTC ASP.NET Core - EJ 2 3
loading
Tags: DataGrid
luigi
Asked On December 13, 2018 09:50 AM UTC

Hello,
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?

Thanks

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

@using Syncfusion.EJ2;
@Html.AntiForgeryToken()

    <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" })"
              gridLines="Both">
        <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-columns>
            <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())"*@
               ..........
        </e-grid-columns>
    </ejs-grid>
}

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

    function dataBound(args) {
        this.autoFitColumns();
    }

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();
            }
            else
            {
                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)
        {
            context.Anagrafica.Add(value.Value);
            context.SaveChanges();
            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)
            {
                context.Anagrafica.Update(value.Value);

                context.SaveChanges();
            }
            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)
            {
                context.Anagrafica.Remove(entity);
            }
            context.SaveChanges();
            return new JsonResult(value);
        }


    }
}



Mohammed Farook J [Syncfusion]
Replied On 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. 
 
Regards, 
J Mohammed Farook 


luigi
Replied On December 14, 2018 03:09 PM UTC

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

Mohammed Farook J [Syncfusion]
Replied On 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. 
 
Regards, 
J Mohammed Farook 


CONFIRMATION

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

This page will automatically be redirected to the 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

;