Example of Button Group in ASP.NET MVC ButtonGroup Control
The following sample demonstrates the default functionalities of normal, radio, and checkbox button groups.
@Html.UiButtonGroup(new UiButtonGroupOptions
{
Id = "icon",
Items = { new UiButtonGroupItem { Id = "watch", IconCss = "ui-icon-watch", Title = "Watch" }, new UiButtonGroupItem { Id = "star", IconCss = "ui-icon-star", Title = "Star" }, new UiButtonGroupItem { Id = "download", IconCss = "ui-icon-download", Title = "Download" } }
})
@Html.UiButtonGroup(new UiButtonGroupOptions
{
Id = "text", Mode = UiButtonGroupMode.Single, Name = "align",
Items = { new UiButtonGroupItem { Id = "left", Text = "Left", Value = "left" }, new UiButtonGroupItem { Id = "middle", Text = "Middle", Value = "middle" }, new UiButtonGroupItem { Id = "right", Text = "Right", Value = "right" } }
})
@Html.UiButtonGroup(new UiButtonGroupOptions
{
Id = "iconandtext", Mode = UiButtonGroupMode.Multiple, Name = "fontstyle",
Items =
{
new UiButtonGroupItem { Id = "bold", Text = "Bold", IconCss = "ui-icon-bold", Value = "bold", Checked = true },
new UiButtonGroupItem { Id = "italic", Text = "Italic", IconCss = "ui-icon-italic", Value = "italic" },
new UiButtonGroupItem { Id = "underline", Text = "Underline", IconCss = "ui-icon-underline", Value = "underline" }
}
})
<style>
.button-group-container { max-width: 420px; margin: 0 auto; padding: 16px 0; }
.button-group-container .row { margin-bottom: 24px; }
.button-group-container .h5 { font-size: 16px; font-weight: 600; margin: 0 0 8px; }
</style>
<div class="control-section">
<div class="button-group-section button-group-container">
<div id="button-group-control">
<div class="row">
<p class="h5">Default</p>
@Html.UiButtonGroup(new UiButtonGroupOptions
{
Id = "icon",
Items = { new UiButtonGroupItem { Id = "watch", IconCss = "ui-icon-watch", Title = "Watch" }, new UiButtonGroupItem { Id = "star", IconCss = "ui-icon-star", Title = "Star" }, new UiButtonGroupItem { Id = "download", IconCss = "ui-icon-download", Title = "Download" } }
})
</div>
<div class="row">
<p class="h5">Single selection</p>
@Html.UiButtonGroup(new UiButtonGroupOptions
{
Id = "text", Mode = UiButtonGroupMode.Single, Name = "align",
Items = { new UiButtonGroupItem { Id = "left", Text = "Left", Value = "left" }, new UiButtonGroupItem { Id = "middle", Text = "Middle", Value = "middle" }, new UiButtonGroupItem { Id = "right", Text = "Right", Value = "right" } }
})
</div>
<div class="row">
<p class="h5">Multiple selection</p>
@Html.UiButtonGroup(new UiButtonGroupOptions
{
Id = "iconandtext", Mode = UiButtonGroupMode.Multiple, Name = "fontstyle",
Items =
{
new UiButtonGroupItem { Id = "bold", Text = "Bold", IconCss = "ui-icon-bold", Value = "bold", Checked = true },
new UiButtonGroupItem { Id = "italic", Text = "Italic", IconCss = "ui-icon-italic", Value = "italic" },
new UiButtonGroupItem { Id = "underline", Text = "Underline", IconCss = "ui-icon-underline", Value = "underline" }
}
})
</div>
</div>
</div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class ButtonController : Controller
{
// The page is Views/Button/ButtonGroup.cshtml; it draws what ViewData holds.
public ActionResult ButtonGroup()
{
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>
ButtonGroup is a graphical user interface that groups series of buttons horizontally or vertically. This supports radio and checkbox type behaviors.
The above sample demonstrates the behaviors of button groups with icon only, text only, and text with icon combinations.
- Default: Triggers action on button click.
- Single selection: Radio type behavior selects a single button and submits its value to the server on form submission.
- Multiple selection: Checkbox type behavior selects multiple buttons and submits its selected values to the server on form submission. This is showcased with the first button selected, by default.