Example of Custom Palettes in ASP.NET MVC ColorPicker Control
This sample demonstrates how to customize the color palettes with different types and styles.
@Html.UiColorPicker("circle-palette", new UiColorPickerOptions { Mode = UiColorPickerMode.Palette, ModeSwitcher = false, Inline = true, ShowButtons = false, Columns = 4, PresetColors = (string[])ViewData["circlePaletteColors"], OnChange = "onChange" })
@Html.UiColorPicker("rounded-palette", new UiColorPickerOptions { Mode = UiColorPickerMode.Palette, ModeSwitcher = false, Inline = true, ShowButtons = false, Columns = 5, PresetColors = (string[])ViewData["roundedPaletteColors"], OnChange = "onChange" })
@Html.UiColorPicker("square-palette", new UiColorPickerOptions { Mode = UiColorPickerMode.Palette, ModeSwitcher = false, Inline = true, ShowButtons = false, Columns = 8, PresetColors = (string[])ViewData["squarePaletteColors"], OnChange = "onChange" })
@Html.UiColorPicker("scroll-palette", new UiColorPickerOptions { Mode = UiColorPickerMode.Palette, ModeSwitcher = false, Inline = true, ShowButtons = false, Columns = 4, PresetColors = (string[])ViewData["scrollPaletteColors"], OnChange = "onChange" })
<style>
#default-control, #inline-control, #custom-control, #colorpicker-control { text-align: center; padding: 20px 0; }
#default-control h4, #colorpicker-control h4, #inline-control h4 { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
.color-preview { width: 120px; height: 80px; margin: 0 auto 16px; border: 1px solid var(--ui-border); border-radius: 8px; background: #008000; }
.color-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 28px; }
.property-section .property-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.property-section .prop-input { width: 110px; padding: 4px 6px; border: 1px solid var(--ui-input-border); border-radius: var(--ui-radius); background: var(--ui-surface); color: var(--ui-text); font: inherit; }
.e-circle-wrap .ui-cp-tile { border-radius: 50%; width: 28px; height: 28px; margin: 2px; }
.e-rounded-wrap .ui-cp-tile { border-radius: 8px; width: 30px; height: 30px; margin: 2px; }
.e-square-wrap .ui-cp-tile { border-radius: 0; width: 24px; height: 24px; }
.e-scroll-wrap .ui-cp-palette { max-height: 150px; overflow-y: auto; }
</style>
<div class="control-section">
<div id="custom-control">
<div id="e-shirt-preview" class="color-preview"></div>
<div id="custom-content" class="color-row">
<div class="e-circle-wrap">
@Html.UiColorPicker("circle-palette", new UiColorPickerOptions { Mode = UiColorPickerMode.Palette, ModeSwitcher = false, Inline = true, ShowButtons = false, Columns = 4, PresetColors = (string[])ViewData["circlePaletteColors"], OnChange = "onChange" })
</div>
<div class="e-rounded-wrap">
@Html.UiColorPicker("rounded-palette", new UiColorPickerOptions { Mode = UiColorPickerMode.Palette, ModeSwitcher = false, Inline = true, ShowButtons = false, Columns = 5, PresetColors = (string[])ViewData["roundedPaletteColors"], OnChange = "onChange" })
</div>
<div class="e-square-wrap">
@Html.UiColorPicker("square-palette", new UiColorPickerOptions { Mode = UiColorPickerMode.Palette, ModeSwitcher = false, Inline = true, ShowButtons = false, Columns = 8, PresetColors = (string[])ViewData["squarePaletteColors"], OnChange = "onChange" })
</div>
<div class="e-scroll-wrap">
@Html.UiColorPicker("scroll-palette", new UiColorPickerOptions { Mode = UiColorPickerMode.Palette, ModeSwitcher = false, Inline = true, ShowButtons = false, Columns = 4, PresetColors = (string[])ViewData["scrollPaletteColors"], OnChange = "onChange" })
</div>
</div>
</div>
</div>
<script>
// Syncfusion: the preview takes the colour picked in any palette
function onChange(args) { document.getElementById('e-shirt-preview').style.backgroundColor = args.value; }
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class ColorPickerController : Controller
{
// The page is Views/ColorPicker/Custom.cshtml; it draws what ViewData holds.
public ActionResult Custom()
{
ViewData["circlePaletteColors"] = new string[] { "#f44336", "#e91e63", "#9c27b0", "#673ab7", "#2196f3", "#03a9f4", "#00bcd4", "#009688", "#8bc34a", "#cddc39", "#ffeb3b", "#ffc107" };
ViewData["squarePaletteColors"] = new string[] { "#b80000", "#db3e00", "#fccb00", "#008b02", "#006b76", "#1273de", "#004dcf", "#5300eb", "#eb9694", "#fad0c3", "#fef3bd", "#c1e1c5", "#bedadc", "#c4def6", "#bed3f3", "#d4c4fb" };
ViewData["roundedPaletteColors"] = new string[] { "#ff6900", "#fcb900", "#7bdcb5", "#00d084", "#8ed1fc", "#0693e3", "#abb8c3", "#eb144c", "#f78da7", "#9900ef" };
ViewData["scrollPaletteColors"] = new string[] { "#ef9a9a", "#e57373", "#ef5350", "#f44336", "#f48fb1", "#f06292", "#ec407a", "#e91e63", "#ce93d8", "#ba68c8", "#ab47bc", "#9c27b0", "#b39ddb", "#9575cd", "#7e57c2", "#673ab7", "#9fa8da", "#7986cb", "#5c6bc0", "#3f51b5", "#90caf9", "#64b5f6", "#42a5f5", "#2196f3", "#81d4fa", "#4fc3f7", "#29b6f6", "#03a9f4", "#80deea", "#4dd0e1", "#26c6da", "#00bcd4", "#80cbc4", "#4db6ac", "#26a69a", "#009688", "#a5d6a7", "#81c784", "#66bb6a", "#4caf50", "#c5e1a5", "#aed581", "#9ccc65", "#8bc34a", "#e6ee9c", "#dce775", "#d4e157", "#cddc39", "#fff59d", "#fff176", "#ffee58", "#ffeb3b", "#ffe082", "#ffd54f", "#ffca28", "#ffc107", "#ffcc80", "#ffb74d", "#ffa726", "#ff9800", "#ffab91", "#ff8a65", "#ff7043", "#ff5722" };
return View();
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
The ColorPicker component is a user interface to select and adjust color values. This supports various color specifications like RGB (Red Green Blue), HSV (Hue Saturation Value), and Hex codes.
In this sample,
- Select the shirt color from different customized palettes. It contains circle, square, rounded edge, and multiple scroll palettes.
- Using the
presetColorsproperty, you can specify the custom colors to be loaded.