ComboBox
Item Template
Features
Sample
Description
This sample shows how to use ItemTemplateId to specify custom content in ComboBox.
Source
ItemTemplateController.cs
using Microsoft.AspNetCore.Mvc; namespace MvcExplorer.Controllers { public partial class ComboBoxController : Controller { public ActionResult ItemTemplate() { var list = GetSystemColors(); return View(list); } } }
ItemTemplate.cshtml
@model IEnumerable<NamedColor> @section Styles{ <style> .palette { display: inline-block; border: 1px solid black; width: 20px; height: 10px; } .palette-label { margin-left: 5px; } </style> } <div> <label>@Html.Raw(ComboBoxRes.ItemTemplate_Colors)</label> <c1-combo-box display-member-path="Name" selected-value-path="Value"> <c1-input-item-template> <span> <span class="palette" style="background-color: {{Name}}"></span> <span class="palette-label">{{Name}}</span> </span> </c1-input-item-template> <c1-items-source source-collection="@Model"></c1-items-source> </c1-combo-box> </div> @section Description{ <p>@Html.Raw(ComboBoxRes.ItemTemplate_Text0)</p> }
Documentation