ListBox
Complex Type
This sample shows how to bind to a list of complex type using "DisplayMemberPath" and "SelectedValuePath".
Features
Black
DarkBlue
DarkGreen
DarkCyan
DarkRed
DarkMagenta
DarkYellow
Gray
DarkGray
Blue
Green
Cyan
Red
Magenta
Yellow
White
Description
This sample shows how to bind to a list of complex type using "DisplayMemberPath" and "SelectedValuePath".
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | using System; using System.Linq; using Microsoft.AspNetCore.Mvc; using MvcExplorer.Models; namespace MvcExplorer.Controllers { public partial class ListBoxController : Controller { public ActionResult ComplexType() { var list = GetSystemColors(); return View(list); } private static NamedColor[] GetSystemColors() { return Enum.GetValues( typeof (ConsoleColor)) .Cast<ConsoleColor>() .Select(c => new NamedColor { Name = c.ToString(), Value = ( int )c }) .ToArray(); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 | @model IEnumerable< NamedColor > < div > < label > @Html .Raw(ListBoxRes.ComplexType_Text0)</ label > < c1-list-box display-member-path = "Name" selected-value-path = "Value" style = "height:200px; width:250px" > < c1-items-source source-collection = "@Model" ></ c1-items-source > </ c1-list-box > </ div > @section Description{ @Html .Raw(ListBoxRes.ComplexType_Text1) } |