下面是一个简单的代码示例,显示了如何实现上述解决方案:
@if (SelectedItems != null && SelectedItems.Count > 0)
{
@foreach (var item in SelectedItems)
{
@item
}
}
else
{
Select Items
}
@if (IsDropdownOpen)
{
}
/* MultiSelectDropdown.css */
.dropdown {
position: relative;
display: inline-block;
}
.selected-items {
border: 1px solid #ddd;
padding: 5px;
min-width: 200px;
}
.selected-items .placeholder {
color: #bbb;
}
.dropdown-menu {
position: absolute;
top: 100%;
left: 0;
z-index: 999;
background-color: #f9f9f9;
border: 1px solid #ddd;
padding: 5px;
max-height: 200px;
overflow-y: auto;
}
.dropdown-item {
padding: 5px;
cursor: pointer;
}
.dropdown-item:hover {
background-color: #ddd;
}
.checkmark {