MultiSelect HtmlHelper Overview

The MultiSelect HtmlHelper extension is a server-side wrapper for the Kendo UI MultiSelect widget.

It allows you to configure the Kendo UI MultiSelect widget from server-side code. The MultiSelect displays a list of options and allows multiple selections from this list. The widget represents a richer version of the <select> element and provides support for local and remote data binding, item and tag templates, and configurable options for controlling the list behavior.

Basic Usage

The following example demonstrates how to define the MultiSelect by using the MultiSelect HtmlHelper.

    @(Html.Kendo().MultiSelect()
        .Name("multiselect")
        .DataTextField("ProductName")
        .DataValueField("ProductID")
        .Value(new[] { 2, 7 })
        .DataSource(source =>
        {
            source.Read(read =>
            {
                read.Action("Products_Read", "Home");
            })
            .ServerFiltering(true);
        })
    )
    public class MultiSelectController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }

        public JsonResult Products_Read(string text)
        {
            var result = GetProducts();

            if (!string.IsNullOrEmpty(text))
            {
                result = result.Where(p => p.ProductName.Contains(text)).ToList();
            }

            return Json(result);
        }

        private static IEnumerable<ProductViewModel> GetProducts()
        {
            var result = Enumerable.Range(0, 50).Select(i => new ProductViewModel
            {
                ProductID = "" + i,
                ProductName = "Product " + i
            });

            return result;
        }
    }

Configuration

The following example demonstrates the basic configuration of the MultiSelect HtmlHelper. To get a reference to an existing Kendo UI MultiSelect instance, use the jQuery.data() configuration option. Once a reference is established, use the MultiSelect API to control its behavior.

@(Html.Kendo().MultiSelect()
    .Name("multiselect")
    .DataTextField("ProductName")
    .DataValueField("ProductID")
    .Placeholder("Select product...")
    .ItemTemplate("<span class=\"product-id-id\">#= ProductID #</span> #= ProductName #")
    .Value(new[] { 2, 7 })
    .Height(520)
    .TagMode(MultiSelectTagMode.Single)
    .DataSource(source =>
    {
        source.Read(read =>
        {
            read.Action("Products_Read", "Home");
        })
        .ServerFiltering(true);
    })
    .Events(events => events
        .Change("onChange")
        .Select("onSelect")
        .Deselect("onDeselect")
        .Open("onOpen")
        .Close("onClose")
        .DataBound("onDataBound")
        .Filtering("onFiltering")
    )
)

<script type="text/javascript">
    $(function () {
        //Notice that the Name() of the MultiSelect is used to get its client-side instance.
        var multiselect = $("#multiselect").data("kendoMultiSelect");
    });
</script>

Event Handling

You can subscribe to all MultiSelect events.

By Handler Name

The following example demonstrates how to subscribe to events by a handler name.

Example
@(Html.Kendo().MultiSelect()
    .Name("multiselect")
    .BindTo(new string[] { "Item1", "Item2", "Item3" })
    .Events(e => e
        .Select("multiselect_select")
        .Change("multiselect_change")
    )
)
<script>
    function multiselect_select() {
        //Handle the select event.
    }

    function multiselect_change() {
        //Handle the change event.
    }
</script>

By Template Delegate

The following example demonstrates how to subscribe to events by a template delegate.

Example
@(Html.Kendo().MultiSelect()
    .Name("multiselect")
    .BindTo(new string[] { "Item1", "Item2", "Item3" })
    .Events(e => e
        .Select(@<text>
            function() {
                //Handle the select event inline.
            }
        </text>)
        .Change(@<text>
            function() {
                //Handle the change event inline.
            }
        </text>)
    )
)

See Also

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