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.

   @(Html.Kendo().ListBox()
        .Name("optional")
        .Toolbar(toolbar =>
        {
            toolbar.Position(Kendo.Mvc.UI.Fluent.ListBoxToolbarPosition.Right);
            toolbar.Tools(tools => tools
                .MoveUp()
                .MoveDown()
            );
        })
        .BindTo(ViewBag.Attendees)
    )
    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.

@(Html.Kendo().ListBox()
    .Name("listbox")
    .Toolbar(toolbar => toolbar.Tools(
        tools => tools
            .MoveUp()
            .MoveDown()
            .Remove()
     ))
    .DataValueField("ProductID")
    .DataTextField("ProductName")
    .DataSource(source => source
        .Read(r => r.Action("GetProducts", "ListBox"))
    )
)

See Also

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