Example of drag and drop functionalities in ASP.NET MVC Chips Control
This ASP.NET MVC Chips sample demonstrates the drag and drop functionality of Chips. To drag and drop a chip element, select and drag the desired chip and drop it at the target index within the required container.
Customize your order with add-ons
Extra cheese
Spicy Level: Medium
Spicy Level: Low
Fast Delivery
Gift Wrapping
Eco-Friendly Packaging
@Html.UiChipList(new UiChipListOptions
{
Id = "choice-container", AllowDragAndDrop = true,
Chips =
{
new UiChip { Text = "Extra cheese", Color = UiButtonColor.Info },
new UiChip { Text = "Spicy Level: Medium", Color = UiButtonColor.Danger },
new UiChip { Text = "Spicy Level: Low", Color = UiButtonColor.Success },
new UiChip { Text = "Fast Delivery", Color = UiButtonColor.Warning },
new UiChip { Text = "Gift Wrapping", Color = UiButtonColor.Primary },
new UiChip { Text = "Eco-Friendly Packaging", Color = UiButtonColor.Success }
}
})
@Html.UiChipList(new UiChipListOptions { Id = "selection-container", AllowDragAndDrop = true })
<style>
#chip-draganddrop-wrapper { max-width: 640px; margin: 0 auto; }
.chips-headers { font-size: 16px; font-weight: 600; margin: 20px 0 8px; }
.sample-padding .ui-chip-list { min-height: 52px; margin-bottom: 16px; padding: 8px; border: 1px dashed var(--ui-border); border-radius: 6px; }
</style>
<div class="control-section">
<div id="chip-draganddrop-wrapper">
<div class="chips-headers">Customize your order with add-ons</div>
<div class="sample-padding">
@Html.UiChipList(new UiChipListOptions
{
Id = "choice-container", AllowDragAndDrop = true,
Chips =
{
new UiChip { Text = "Extra cheese", Color = UiButtonColor.Info },
new UiChip { Text = "Spicy Level: Medium", Color = UiButtonColor.Danger },
new UiChip { Text = "Spicy Level: Low", Color = UiButtonColor.Success },
new UiChip { Text = "Fast Delivery", Color = UiButtonColor.Warning },
new UiChip { Text = "Gift Wrapping", Color = UiButtonColor.Primary },
new UiChip { Text = "Eco-Friendly Packaging", Color = UiButtonColor.Success }
}
})
@Html.UiChipList(new UiChipListOptions { Id = "selection-container", AllowDragAndDrop = true })
</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 ChipsController : Controller
{
// The page is Views/Chips/DragAndDrop.cshtml; it draws what ViewData holds.
public ActionResult DragAndDrop()
{
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 Chips control allows users to drag any chip and drop it on any index in a container using AllowDragAndDrop property. Additionally, it supports dropping a chip to an external chips container.