Getting Started

17 Feb 20223 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 MVC application to use our components.

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

Initialize MultiSelect control to the Application

MultiSelect control can be rendered by using the EJS().MultiSelect() tag helper in ASP.NET MVC application. Add the below simple code to your index.cshtml page which is available within the Views/Home folder, to initialize the MultiSelect.

@Html.EJS().MultiSelect("default").DataSource((IEnumerable<object>)ViewBag.data).Render()
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();
        }
    }
}

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

Binding data source

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

The following example illustrates the output in your browser.

@Html.EJS().MultiSelect("default").Placeholder("Select games").DataSource((IEnumerable<object>)ViewBag.data).PopupHeight("220px").Render()
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 MultiSelect input element’s width, and the height auto adjust’s according to the height of the popup list items.

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

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

@Html.EJS().MultiSelect("default").Placeholder("Select games").DataSource((IEnumerable<object>)ViewBag.data).PopupHeight("220px").PopupWidth("300px").Render()
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