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

AutoComplete With WebApi

Dear Syncfusion, 

I want to fill autocomplete using web API. I followed this thread https://www.syncfusion.com/forums/124804/searching-existing-api-using-autocomplete
but unfortunately, it seems doesn't work for EJ2. 

 function OnCustomerChange(args) {
            if (args.value != "") {
                    type: "GET",
                    url: "https://localhost:5201/api/v1/Customer/WithName/" + args.value,
                    contentType: "application/json; charset=utf-8",
                    crossdomain: true,
                    dataType: "json",
                    success: OnCustomerAjaxSuccess,
                    failure: function (response) {

How to populate to AutoComplete control ? 


1 Reply

BC Berly Christopher Syncfusion Team September 2, 2019 12:32 PM UTC

Hi Hendi, 
Greetings from Syncfusion support.  
We would like to inform you that we have provided the Web API Adaptor support for AutoComplete component instead of AJAX call as mentioned in the below code example. 
<h4>Auto Complete with Web API Adaptor using API</h4> 
        <ejs-autocomplete id="games" placeholder="Select a Game"> 
            <e-data-manager url="/api/Default/" adaptor="WebApiAdaptor"></e-data-manager> 
Create the API controller and paste the below content to achieve your requirement. 
public class DefaultController : ControllerBase 
        List<string> game = new List<string>(); 
        // GET: api/Default 
        public List<string> Get() 
                return game; 
Else, if you want to set the data source with AJAX call, we suggest you to use the below mentioned code example to achieve your requirement in the created event of the AutoComplete component.  
   <h4>Auto Complete with Web API Adaptor using Ajax call</h4> 
        <ejs-autocomplete id="autoComplete" created="onCreate" placeholder="Employee Name" autofill="true" noRecordsTemplate="@Html.Raw("<span class='norecord'> NO DATA AVAILABLE</span>")"> 
       function onCreate(e) {  
        var autoObj = document.getElementById('autoComplete').ej2_instances[0];  
            type: "POST",  
            url: "/Home/FFUploadSiteselected",  
            data: JSON.stringify({ ssite: autoObj.value }),  
            contentType: "application/json; charset=utf-8",  
            dataType: "json",  
            success: function (data) { 
                autoObj.dataSource = data;  
            error: function (response) {  
public class HomeController : Controller 
        List<string> emp = new List<string>(); 
        public object FFUploadSiteselected(string ssite) 
            emp.Add("Andrew Fuller"); 
            emp.Add("Nancy Devolio"); 
            emp.Add("Laura Callahan"); 
            return Json(emp); 
Please find the sample link from below. 
To know more about data binding, please refer the below UG and Demo link. 
Still facing issues, please revert us with issue reproducing sample that will help us to check and provide the exact solution at our end.  
Berly B.C 

Live Chat Icon For mobile
Up arrow icon