Example of Template in ASP.NET MVC Toolbar Control
This sample demonstrates customization of the ASP.Net MVC Toolbar.
@Html.UiNumericTextBox("count", new UiNumericTextBoxOptions { Width = "50px", Min = 0, Max = 100, Value = 1, ShowSpinButton = false, Format = "###.##" })
@Html.UiComboBox("combo-element", new UiComboBoxOptions { Value = "100%", ShowClearButton = false, Width = "85px", PopupWidth = "85px", DataSource = (string[])ViewData["data"] })
@Html.UiTextBox("text-element", null, new UiTextBoxOptions { Width = "125px", Placeholder = "Find Text" })
@Html.UiToolbar(new UiToolbarOptions { Id = "template-Toolbar", CssClass = "template", Items = items, OverflowMode = UiToolbarOverflowMode.Popup })
<style>
/* Toolbar Styles */
.template.ui-toolbar .total-page {
padding-left: 4px;
cursor: default;
font-size: 14px;
vertical-align: middle;
}
.template.ui-toolbar .ui-tb-popup .page-count,
.template.ui-toolbar .ui-tb-popup .selection-tool,
.template.ui-toolbar .ui-tb-popup .find,
.template.ui-toolbar .ui-tb-popup .pan-mode,
.template.ui-toolbar .ui-tb-popup .percentage {
display: none;
}
.e-sample-resize-container { max-width: 760px; margin: 0 auto; }
</style>
@{
// Syncfusion's template items name an element of the page ("#count-textbox"); here the item holds the controls
List<UiToolbarItem> items = (List<UiToolbarItem>)ViewData["templateItems"];
items.Single(i => i.Id == "count-textbox").Template = @<text>@Html.UiNumericTextBox("count", new UiNumericTextBoxOptions { Width = "50px", Min = 0, Max = 100, Value = 1, ShowSpinButton = false, Format = "###.##" })<span class="total-page">of 100</span></text>;
items.Single(i => i.Id == "combo-element").Template = @<text>@Html.UiComboBox("combo-element", new UiComboBoxOptions { Value = "100%", ShowClearButton = false, Width = "85px", PopupWidth = "85px", DataSource = (string[])ViewData["data"] })</text>;
items.Single(i => i.Id == "text-element").Template = @<text>@Html.UiTextBox("text-element", null, new UiTextBoxOptions { Width = "125px", Placeholder = "Find Text" })</text>;
}
<div class="control-section">
<div class="e-sample-resize-container" style="margin-top: 100px">
@Html.UiToolbar(new UiToolbarOptions { Id = "template-Toolbar", CssClass = "template", Items = items, OverflowMode = UiToolbarOverflowMode.Popup })
</div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class ToolbarController : Controller
{
// The page is Views/Toolbar/Template.cshtml; it draws what ViewData holds.
public ActionResult Template()
{
List<UiToolbarItem> templateItems = new List<UiToolbarItem>();
templateItems.Add(new UiToolbarItem { IconCss = "e-icons e-folder", TooltipText = "Open File", Text = "open", ShowTextOn = UiToolbarShowText.Overflow, Align = UiToolbarAlign.Left });
templateItems.Add(new UiToolbarItem { Type = UiToolbarItemType.Separator });
templateItems.Add(new UiToolbarItem { IconCss = "e-icons e-first-page", TooltipText = "Show first page", Text = "First", ShowTextOn = UiToolbarShowText.Overflow, Align = UiToolbarAlign.Left, Disabled=true });
templateItems.Add(new UiToolbarItem { IconCss = "e-icons e-chevron-left", TooltipText = "Show previous page", Text = "Previous", ShowTextOn = UiToolbarShowText.Overflow, Align = UiToolbarAlign.Left, Disabled = true });
templateItems.Add(new UiToolbarItem { IconCss = "e-icons e-chevron-right", TooltipText = "Show next page", Text = "Next", ShowTextOn = UiToolbarShowText.Overflow, Align = UiToolbarAlign.Left });
templateItems.Add(new UiToolbarItem { IconCss = "e-icons e-last-page", TooltipText = "Show last page", Text = "Last", ShowTextOn = UiToolbarShowText.Overflow, Align = UiToolbarAlign.Left });
templateItems.Add(new UiToolbarItem { Id = "count-textbox", Type = UiToolbarItemType.Input, CssClass = "page-count" });
templateItems.Add(new UiToolbarItem { Type = UiToolbarItemType.Separator });
templateItems.Add(new UiToolbarItem { IconCss = "e-icons e-zoom-out", TooltipText = "Zoom-Out", Text = "Bold", ShowTextOn = UiToolbarShowText.Overflow, Align = UiToolbarAlign.Left });
templateItems.Add(new UiToolbarItem { IconCss = "e-icons e-zoom-in", TooltipText = "Underline", Text = "Underline", ShowTextOn = UiToolbarShowText.Overflow, Align = UiToolbarAlign.Left });
templateItems.Add(new UiToolbarItem { Id = "combo-element", Type = UiToolbarItemType.Input, CssClass = "percentage" });
templateItems.Add(new UiToolbarItem { Type = UiToolbarItemType.Separator });
templateItems.Add(new UiToolbarItem { IconCss = "e-icons e-mouse-pointer", TooltipText = "Text Selection Tool", Text = "Text", ShowTextOn = UiToolbarShowText.Overflow, Align = UiToolbarAlign.Left });
templateItems.Add(new UiToolbarItem { IconCss = "e-icons e-pan", TooltipText = "Pan Mode", Text = "Pan Mode", ShowTextOn = UiToolbarShowText.Overflow, Align = UiToolbarAlign.Left });
templateItems.Add(new UiToolbarItem { Type = UiToolbarItemType.Separator });
templateItems.Add(new UiToolbarItem { IconCss = "e-icons e-undo", TooltipText = "Undo", Text = "Undo", ShowTextOn = UiToolbarShowText.Overflow, Align = UiToolbarAlign.Left });
templateItems.Add(new UiToolbarItem { IconCss = "e-icons e-redo", TooltipText = "Redo", Text = "Redo", ShowTextOn = UiToolbarShowText.Overflow, Align = UiToolbarAlign.Left });
templateItems.Add(new UiToolbarItem { Type = UiToolbarItemType.Separator });
templateItems.Add(new UiToolbarItem { IconCss = "e-icons e-comment", TooltipText = "Add Comments", Text = "Add", ShowTextOn = UiToolbarShowText.Overflow, Align = UiToolbarAlign.Left });
templateItems.Add(new UiToolbarItem { Type = UiToolbarItemType.Separator });
templateItems.Add(new UiToolbarItem { Text = "Submit", Align = UiToolbarAlign.Left });
templateItems.Add(new UiToolbarItem { Id = "text-element", Type = UiToolbarItemType.Input, CssClass = "find", Align = UiToolbarAlign.Right, Overflow = UiToolbarOverflowOption.Show });
templateItems.Add(new UiToolbarItem { IconCss = "e-icons e-annotation-edit", TooltipText = "Edit Annotations", Text = "Edit", ShowTextOn = UiToolbarShowText.Overflow, Align = UiToolbarAlign.Right });
templateItems.Add(new UiToolbarItem { IconCss = "e-icons e-print", TooltipText = "Print File", Text = "Print", ShowTextOn = UiToolbarShowText.Overflow, Align = UiToolbarAlign.Right });
templateItems.Add(new UiToolbarItem { IconCss = "e-icons e-download", TooltipText = "Download File", Text = "Download", ShowTextOn = UiToolbarShowText.Overflow, Align = UiToolbarAlign.Right });
ViewData["templateItems"] = templateItems;
ViewData["data"] = new string[] { "25%", "50%", "75%", "100%" };
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>
In this demo, the ASP.Net MVC Toolbar showcases customization options for toolbar items using the template property. The Toolbar items are arranged using the align property.
To add icons to the toolbar items, the prefixIcon property is used. When the showTextOn property's is set to overflow, the Toolbar items' text that overflows will be visible.
In this demo, NumericTextBox, ComboBox and TextBox are used inside the Toolbar .