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

WebAPI not working

I have created a simple .aspx page to show a grid. My requirement is that the entire data should not be loaded at first (except for the first page) but when user clicks on next page and so on the data should come from an API.

I have created the same code as given in the documentation. Now the problem is that the API is called but at the end it includes a forward slash before the query string. You can see below:



 The following is my code.

HTML:
<div id="grid"></div>

JAVASCRIPT:
var dataManager = ej.DataManager({
    url:"/api/Designs",
    adaptor: new ej.WebApiAdaptor()
});

$("#grid").ejGrid({               
    dataSource: dataManager,
    allowPaging: true                                            
});          

C# API:
using Some.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;

namespace Some.Sales
{
    public class DesignsController : ApiController
    {
        // GET api/design
        public object Get()
        {           
            var queryString = HttpContext.Current.Request.QueryString;

            int skip = Convert.ToInt32(queryString["$skip"]);
            int take = Convert.ToInt32(queryString["$top"]);

            var designs = new DesignRepository().GetDesignAll().ToList();

            return new {
                Items = designs.Skip(skip).Take(take),
                Count = designs.Count
            };           
        }      
    }
}

Where i am doing wrong, please help me out.



5 Replies

PK Prasanna Kumar Viswanathan Syncfusion Team July 28, 2016 12:24 PM UTC

Hi Mohammed, 

Thanks for contacting Syncfusion support. 

We checked with our sample with the given code snippet and we unable to reproduce the mentioned issue. 

To reproduce the issue we need the following details, 

1. Did you face the same issue in other browsers? 

2. Essential Studio Version details. 

3. If possible, reproduce the issue in the attached sample. 


Regards, 
Prasanna Kumar N.S.V 
 



TB Tomasz Bednarek March 4, 2020 01:57 PM UTC

This issue is old, but I ran into a similar problem with EJ2. The problem lies in the trailing slash in the url that the DM/WebApiAdaptor attach to the endpoint url. I don't know the reason, but it's causing problems also for me.


SK Sujith Kumar Rajkumar Syncfusion Team March 6, 2020 10:44 AM UTC

Hi Tomasz, 
 
The slash character will be added to each request before the query string with the web api adaptor request which is the behavior. Even with or without this slash the controller’s method can be accessed without any problems. 
 
However if you wish to remove this slash added before the query string then you can achieve this by using custom adaptor to override its ProcessQuery method and modify the request URL. This is demonstrated in the below code snippet, 
 
class CustomAdaptor extends ej.data.WebApiAdaptor { 
        processQuery() { 
            // calling base class processQuery function 
            var original = super.processQuery.apply(this, arguments); 
            // Removing slash before query string and updating in the request url 
            var slash = original.url.lastIndexOf('/'); 
            var newUrl = original.url.slice(0, slash) + original.url.slice(slash + 1); 
            original.url = newUrl; 
            // Return the updated request query 
            return original; 
        } 
} 
 
$(function () { 
        var data = new ej.data.DataManager({ 
            url: '/api/Orders', 
            adaptor: new CustomAdaptor() 
        }); 
 
        var grid = new ej.grids.Grid({ 
            dataSource: data, 
                   . 
                   . 
        }); 
}); 
 
We have prepared a sample based on this for your reference which you can find below, 
 
 
Let us know if you have any concerns. 
 
Regards, 
Sujith R 



AL Albert Labarento February 3, 2021 01:17 PM UTC

This seems to be ugly, and additional work for us to add a CustomAdaptor just to get rid of the trailing comma, since most of api endpoints will fail if a trailing comma was added at the end, if they want a trailing comma they can just add it in the url option


SK Sujith Kumar Rajkumar Syncfusion Team February 4, 2021 11:14 AM UTC

Hi Albert, 
 
Greetings from Syncfusion support. 
 
We checked your query and based on that would like to let you know that when Web API adaptor is bound to the Grid, the data request will be sent as per the Web API standards by default. And since the previous query was to remove the default trailing slash character that is sent in the request, we had provided suggestion to use the custom adaptor for the same. So if any additional information needs to be sent along with the server request, the custom adaptor’s ProcessQuery method can be used. 
 
But it will not send trailing comma as you have mentioned, so can you please share us the following information to validate further on this, 
 
  • Let us know when this trailing comma is sent along with the request in your case.
  • Network tab request and response details.
  • Grid code file.
  • Syncfusion package version used.
 
Regards, 
Sujith R 


Loader.
Live Chat Icon For mobile
Up arrow icon