ComboBox
Item Template
Features
Sample
Description
This sample shows how to use ItemTemplateId to specify custom content in ComboBox.
Source
ItemTemplateController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.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>
}
<script id="template1" type="text/template">
<span>
<span class="palette" style="background-color: {{Value}}"></span>
<span class="palette-label">{{Name}}</span>
</span>
</script>
<div>
<label>@Html.Raw(Resources.ComboBox.ItemTemplate_Colors)</label>
@(Html.C1().ComboBox()
.Bind(Model)
.DisplayMemberPath("Name")
.SelectedValuePath("Value")
.ItemTemplateId("template1")
.Width(250)
)
</div>
@section Description{
<p>@Html.Raw(Resources.ComboBox.ItemTemplate_Text0)</p>
}
Documentation