Data Binding

The ListBox enables you to perform server binding and Ajax binding.

Server Binding

During the server data-binding mode, the data is serialized to the client and no Ajax requests are made. The following example demonstrates how to bind the ListBox on the server when you use static data.

        .Toolbar(toolbar =>
            toolbar.Tools(tools => tools
    public ActionResult Index()
        ViewBag.Attendees = new List<string>
            "Steven White",
            "Nancy King",
            "Nancy Davolio",
            "Robert Davolio",
            "Michael Leverling",
            "Andrew Callahan",
            "Michael Suyama"
        return View();

Ajax Binding

During the Ajax binding the ListBox makes Ajax requests to get the data. The following example demonstrates how to bind the DataSource component to remote data.

When you use complex data objects, set the DataTextField("TextField") and DataValueField("ValueField") properties to notify the ListBox of your preferred binding behavior.

    .Toolbar(toolbar => toolbar.Tools(
        tools => tools
    .DataSource(source => source
        .Read(r => r.Action("GetProducts", "ListBox"))

See Also

In this article
Not finding the help you need? Improve this article