- Primitive Data Types
- Object Data Types
Contact Support
Value binding in AutoComplete Component
7 Jun 20243 minutes to read
Value binding in the AutoComplete control allows you to associate data values with each list item. This facilitates managing and retrieving selected values efficiently. The AutoComplete component provides flexibility in binding both primitive data types and complex objects.
Primitive Data Types
The AutoComplete control provides flexible binding capabilities for primitive data types like strings and numbers. You can effortlessly bind local primitive data arrays, fetch and bind data from remote sources, and even custom data binding to suit specific requirements. Bind the value of primitive data to the value property of the AutoComplete.
Primitive data types include:
- String
- Number
- Boolean
- Null
The following sample shows the example for preselect values for primitive data type
@Html.EJS().AutoComplete("records").Placeholder("Select a item").PopupHeight("200px").DataSource((IEnumerable<object>)ViewBag.data).AllowFiltering(true).Value((string[])ViewBag.value).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 primitive()
{
ViewBag.data = new string[] { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10" };
ViewBag.value = "Item 5";
return View();
}
}
}
Object Data Types
In the AutoComplete control, object binding allows you to bind to a dataset of objects. When allowObjectBinding
is enabled, the value of the control will be an object of the same type as the selected item in the value property. This feature seamlessly binds arrays of objects, whether sourced locally, retrieved from remote endpoints, or customized to suit specific application needs.
The following sample shows the example for preselect values for object data type
@Html.EJS().AutoComplete("records").Placeholder("Select a item").PopupHeight("200px").DataSource((IEnumerable<object>)ViewBag.data).AllowObjectBinding(true).AllowFiltering(true).Value((string[])ViewBag.value).Fields(new Syncfusion.EJ2.DropDowns.AutoCompleteFieldSettings { Value = "Text" }).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 object()
{
ViewBag.data = new Record().RecordModelList();
ViewBag.value = new { ID = "id5", Text = "Item 5" };
return View();
}
}
}