Getting Started

25 Feb 20225 minutes to read

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, you also have to include a license key in your projects. Please refer to this link to know about registering Syncfusion license key in your ASP.NET CORE application to use our controls.

This section briefly explains how to include simple AutoComplete control in your ASP.NET Core application. You can refer to ASP.NET Core Getting Started documentation page for system requirements, and configure common specifications.

Initialize AutoComplete control to the Application

AutoComplete control can be rendered by using the ejs-autocomplete tag helper in ASP.NET Core application. Add the below simple code to your index.cshtml page which is available within the Views/Home folder, to initialize the AutoComplete.

<ejs-autocomplete id="games" dataSource="@ViewBag.data"> </ejs-autocomplete>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplication1.Models;

namespace WebApplication1.Controllers
{
    public class AutoCompleteController : Controller
    {
        public ActionResult arrayofstring()
        {
            ViewBag.data = new string[] { "Badminton", "Basketball", "Cricket", "Football", "Golf", "Gymnastics", "Hockey", "Tennis" };
            return View();
        }
    }
}

Running the above code will display the basic AutoComplete on the browser.

Binding data source

After initialization, populate the AutoComplete with data using the dataSource property. Here, an array of string values is passed to the AutoComplete control.

The following example illustrates the output in your browser.

<ejs-autocomplete id="games" allowCustom="true" dataSource="@ViewBag.data" placeholder="e.g. Basketball" popupHeight="220px">
</ejs-autocomplete>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplication1.Models;

namespace WebApplication1.Controllers
{
    public class AutoCompleteController : Controller
    {
        public ActionResult arrayofstring()
        {
            ViewBag.data = new string[] { "Badminton", "Basketball", "Cricket", "Football", "Golf", "Gymnastics", "Hockey", "Tennis" };
            return View();
        }
    }
}

Custom values

The AutoComplete allows the user to give input as custom value which is not required to present in predefined set of values. By default, this support is enabled by allowCustom property. The custom value will be sent to post back handler when a form is about to be submitted.

<ejs-autocomplete id="games" allowCustom="true" dataSource="@ViewBag.data" placeholder="e.g. Basketball" popupHeight="220px">
</ejs-autocomplete>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplication1.Models;

namespace WebApplication1.Controllers
{
    public class AutoCompleteController : Controller
    {
        public ActionResult arrayofstring()
        {
            ViewBag.data = new string[] { "Badminton", "Basketball", "Cricket", "Football", "Golf", "Gymnastics", "Hockey", "Tennis" };
            return View();
        }
    }
}

Configure the suggestion list

By default, suggestion list width automatically adjusts according to the AutoComplete input element’s width, and the height of the suggestion list has ‘300px’.

The height and width of the popup list can also be customized using the
popupHeight and popupWidth property respectively.

In the following sample, suggestion list’s width and height are configured.

<ejs-autocomplete id="games" dataSource="@ViewBag.data" placeholder="e.g. Basketball" popupWidth="300px" popupHeight="220px">
</ejs-autocomplete>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplication1.Models;

namespace WebApplication1.Controllers
{
    public class AutoCompleteController : Controller
    {
        public ActionResult arrayofstring()
        {
            ViewBag.data = new string[] { "Badminton", "Basketball", "Cricket", "Football", "Golf", "Gymnastics", "Hockey", "Tennis" };
            return View();
        }
    }
}

See Also