Example of Dropdown Button in ASP.NET MVC DropDownButton Control
This sample demonstrates the default functionalities of the DropDownButton. By clicking DropDownButton, it displays popup with list of action items.
@Html.UiDropDownButton(new UiDropDownButtonOptions { Id = "iconbtn", IconCss = "ui-icon-profile", Title = "Profile", Items = (List<UiDropDownItem>)ViewData["datasource"] })
@Html.UiDropDownButton(new UiDropDownButtonOptions { Id = "textbtn", Text = "Profile", Items = (List<UiDropDownItem>)ViewData["datasource"] })
@Html.UiDropDownButton(new UiDropDownButtonOptions { Id = "icontextbtn", Text = "Profile", IconCss = "ui-icon-profile", Items = (List<UiDropDownItem>)ViewData["datasource"] })
@Html.UiDropDownButton(new UiDropDownButtonOptions { Id = "custombtn", Text = "Profile", ShowCaret = false, Items = (List<UiDropDownItem>)ViewData["datasource"] })
<style>
.button-section { padding: 40px 0; }
#button-control { display: flex; flex-wrap: wrap; justify-content: center; gap: 24px 48px; }
</style>
<div class="control-section">
<div class="button-section">
<div id="button-control">
@Html.UiDropDownButton(new UiDropDownButtonOptions { Id = "iconbtn", IconCss = "ui-icon-profile", Title = "Profile", Items = (List<UiDropDownItem>)ViewData["datasource"] })
@Html.UiDropDownButton(new UiDropDownButtonOptions { Id = "textbtn", Text = "Profile", Items = (List<UiDropDownItem>)ViewData["datasource"] })
@Html.UiDropDownButton(new UiDropDownButtonOptions { Id = "icontextbtn", Text = "Profile", IconCss = "ui-icon-profile", Items = (List<UiDropDownItem>)ViewData["datasource"] })
@Html.UiDropDownButton(new UiDropDownButtonOptions { Id = "custombtn", Text = "Profile", ShowCaret = false, Items = (List<UiDropDownItem>)ViewData["datasource"] })
</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/DropDownButton.cshtml; it draws what ViewData holds.
public ActionResult DropDownButton()
{
List<UiDropDownItem> items = new List<UiDropDownItem>();
items.Add(new UiDropDownItem { Text = "Dashboard", IconCss = "ui-icon-dashboard" });
items.Add(new UiDropDownItem { Text = "Notifications", IconCss = "ui-icon-notifications" });
items.Add(new UiDropDownItem { Text = "User Settings", IconCss = "ui-icon-settings" });
items.Add(new UiDropDownItem { Text = "Log Out", IconCss = "ui-icon-logout" });
ViewData["datasource"] = items;
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>
DropDownButton component is used to toggle contextual overlays for displaying list of links that containing action items. It can contain both text and images.
In this sample, DropDownButton contains icon, content and list of action items, icon can be added by using iconCss property, content can be added by using content property and list of action items can be added by using items property.