Getting Started

19 Dec 20224 minutes to read

NOTE

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

This section briefly explains how to include simple DropDownList 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 DropDownList control to the Application

DropDownList control can be rendered by using the ejs-dropdownlist 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 DropDownList.

@{
    ...
    var data = new string[] { "Badminton", "Basketball", "Cricket", "Football", "Golf", "Gymnastics", "Hockey", "Tennis" };
}

<ejs-dropdownlist id="games" dataSource="data"> </ejs-dropdownlist>
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 Index()
        {
            ViewBag.data = new string[] { "Badminton", "Basketball", "Cricket", "Football", "Golf", "Gymnastics", "Hockey", "Tennis" };
            return View();
        }
    }
}

NOTE

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

Binding data source

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

@{
    ...
    var data = new string[] { "Badminton", "Basketball", "Cricket", "Football", "Golf", "Gymnastics", "Hockey", "Tennis" };
}

<ejs-dropdownlist id="games" dataSource="data" placeholder="Select a game" popupHeight="220px">
</ejs-dropdownlist>
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 Index()
        {
            ViewBag.data = new string[] { "Badminton", "Basketball", "Cricket", "Football", "Golf", "Gymnastics", "Hockey", "Tennis" };
            return View();
        }
    }
}

Configure the popup list

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

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

@{
    ...
    var data = new string[] { "Badminton", "Basketball", "Cricket", "Football", "Golf", "Gymnastics", "Hockey", "Tennis" };
}

<ejs-dropdownlist id="games" dataSource="data" popupWidth="300px" placeholder="Select a game" popupHeight="220px">
</ejs-dropdownlist>
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 Index()
        {
            ViewBag.data = new string[] { "Badminton", "Basketball", "Cricket", "Football", "Golf", "Gymnastics", "Hockey", "Tennis" };
            return View();
        }
    }
}

See Also