The MultiSelect control can be customized to display a list of custom objects in the dropdown. This is accomplished by by binding it with a collection of objects using DisplayMemberPath, SelectedValuePath, and CheckedMemberPath properties.
The following image shows a MultiSelect control bound to a collection of Products from a local NorthWind database file C1NWind.mdf.
The following code examples demonstrate how to bind a Multi-select control to a collection of objects:
ComplexTypeController.cs
C# |
Copy Code
|
---|---|
private C1NWindEntities db = new C1NWindEntities(); public ActionResult ComplexType() { return View(db); } |
ComplexType.cshtml
Razor |
Copy Code
|
---|---|
@model C1NWindEntities <br /> <div> <label>MultiSelect bound to an array of objects:</label> @(Html.C1().MultiSelect() .Bind(Model.Products) .Name("products") .DisplayMemberPath("ProductName") .SelectedValuePath("ProductID") .CheckedMemberPath("Discontinued") ) </div> |