Search results

Getting Started

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 ComboBox 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.

Adding component to the Application

  • Add the ComboBox component in view page to render our Syncfusion components.
razor
data.cs
@Html.EJS().ComboBox("games").Placeholder("Select a game").PopupHeight("230px").DataSource((IEnumerable<object>)ViewBag.localdata).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 IActionResult arrayofstring()
        {
            ViewBag.data = new string[] { "Badminton", "Basketball", "Cricket", "Football", "Golf", "Gymnastics", "Hockey", "Tennis" };
            return View();
        }
    }
}

Binding data source

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

The following example illustrates the output in your browser.

razor
data.cs
@Html.EJS().ComboBox("games").Placeholder("Select a game").PopupHeight("230px").DataSource((IEnumerable<object>)ViewBag.localdata).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 IActionResult arrayofstring()
        {
            ViewBag.data = new string[] { "Badminton", "Basketball", "Cricket", "Football", "Golf", "Gymnastics", "Hockey", "Tennis" };
            return View();
        }
    }
}

Custom values

The ComboBox 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. In this case, both text field and value field considered as same. The custom value will be sent to post back handler when a form is about to be submitted.

razor
customvalue.cs
@Html.EJS().ComboBox("games").AllowCustom(true).Placeholder("Select a game").PopupHeight("230px").DataSource((IEnumerable<object>)ViewBag.localdata).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 IActionResult arrayofstring()
        {
            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 ComboBox 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.

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

razor
suggestionlist.cs
@Html.EJS().ComboBox("games").AllowCustom(true).Placeholder("Select a game").PopupWidth("300px").PopupHeight("230px").DataSource((IEnumerable<object>)ViewBag.localdata).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 IActionResult arrayofstring()
        {
            ViewBag.data = new string[] { "Badminton", "Basketball", "Cricket", "Football", "Golf", "Gymnastics", "Hockey", "Tennis" };
            return View();
        }
    }
}