syncfusion-aspnetcore-multiselect

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Implementing MultiSelect in ASP.NET Core

在ASP.NET Core中实现MultiSelect

The MultiSelect is an advanced dropdown component that enables users to select multiple values from a predefined list with features like filtering, templates, checkboxes, grouping, and full accessibility support. This skill guides you through implementing MultiSelect in ASP.NET Core applications using Syncfusion's tag helper syntax.
MultiSelect是一款高级下拉组件,支持用户从预定义列表中选择多个值,具备过滤、模板、复选框、分组和完整无障碍支持等功能。本指南将引导你使用Syncfusion的tag helper语法在ASP.NET Core应用中实现MultiSelect。

When to Use This Skill

何时使用该技能

Use this skill when you need to:
  • Create dropdown fields where users can select multiple options
  • Add search/filter functionality to large option lists
  • Display selected items as chips with remove capability
  • Implement checkboxes for clear multi-selection UI
  • Bind to local arrays or remote data sources
  • Customize list item appearance with templates
  • Group related options by category
  • Ensure WCAG 2.2 accessibility compliance
  • Handle complex selection scenarios (cascading, custom values)
当你需要以下功能时使用本技能:
  • 创建支持用户选择多个选项的下拉字段
  • 为大型选项列表添加搜索/过滤功能
  • 将选中项显示为可移除的芯片(chip)
  • 实现带有清晰多选UI的复选框
  • 绑定到本地数组或远程数据源
  • 使用模板自定义列表项外观
  • 按类别分组相关选项
  • 确保符合WCAG 2.2无障碍标准
  • 处理复杂选择场景(级联、自定义值)

Key Features

核心功能

FeatureUse Case
Multiple SelectionSelect multiple values from dropdown list
Filtering & SearchSearch through large lists efficiently
CheckboxesVisual indication of multi-select with checkbox mode
Data BindingLocal arrays or remote data sources
TemplatesCustomize item appearance and selected value display
GroupingOrganize options into logical categories
SortingAlphabetically sort options (ascending/descending)
Chip DisplayShow selected items as removable chips
Custom ValuesAllow users to add custom selection values
Virtual ScrollingEfficiently handle 1000+ item lists
CascadingLink multiple MultiSelect components
WCAG ComplianceBuilt-in accessibility for screen readers, keyboard nav
EventsRespond to selection changes, opens, closes
功能使用场景
Multiple Selection从下拉列表中选择多个值
Filtering & Search高效搜索大型列表
Checkboxes用复选框模式直观展示多选状态
Data Binding绑定本地数组或远程数据源
Templates自定义项外观和选中值展示样式
Grouping将选项按逻辑类别组织
Sorting按字母顺序对选项排序(升序/降序)
Chip Display将选中项显示为可移除的芯片
Custom Values允许用户添加自定义选择值
Virtual Scrolling高效处理1000+条数据的列表
Cascading关联多个MultiSelect组件
WCAG Compliance内置屏幕阅读器、键盘导航的无障碍支持
Events响应选择变化、组件展开/关闭等事件

Documentation Navigation Guide

文档导航指南

Getting Started

入门指南

📄 Read: references/getting-started.md
  • Prerequisites and system requirements
  • Installing Syncfusion.EJ2.AspNet.Core NuGet package
  • Configuring TagHelper in _ViewImports.cshtml
  • Adding stylesheets and script resources via CDN
  • Registering the script manager
  • Creating your first MultiSelect
  • Running and testing the application
📄 阅读: references/getting-started.md
  • 先决条件和系统要求
  • 安装Syncfusion.EJ2.AspNet.Core NuGet包
  • 在_ViewImports.cshtml中配置TagHelper
  • 通过CDN添加样式表和脚本资源
  • 注册脚本管理器
  • 创建你的第一个MultiSelect
  • 运行和测试应用程序

Tag Helper Syntax

Tag Helper语法

📄 Read: references/tag-helper-syntax.md
  • MultiSelect tag helper structure and properties
  • Essential properties (Placeholder, Value, Readonly, Disabled)
  • Data source binding basics
  • Event binding in tag helpers
  • CSS class customization
  • Best practices and common patterns
📄 阅读: references/tag-helper-syntax.md
  • MultiSelect tag helper的结构和属性
  • 核心属性(Placeholder、Value、Readonly、Disabled)
  • 数据源绑定基础
  • Tag Helper中的事件绑定
  • CSS类自定义
  • 最佳实践和常见模式

Data Binding

数据绑定

📄 Read: references/data-binding.md
  • Binding to local array of strings
  • Binding to array of objects
  • Complex object binding with nested fields
  • Remote data sources with DataManager
  • Field mapping (text, value, groupBy)
  • Dynamic data loading and refresh patterns
📄 阅读: references/data-binding.md
  • 绑定到字符串类型的本地数组
  • 绑定到对象数组
  • 嵌套字段的复杂对象绑定
  • 使用DataManager绑定远程数据源
  • 字段映射(text、value、groupBy)
  • 动态数据加载和刷新模式

Filtering and Search

过滤与搜索

📄 Read: references/filtering-and-search.md
  • Built-in search box functionality
  • Filter type options (contains, startswith, endswith)
  • Custom filter logic with server-side filtering
  • Filter templates for advanced search UI
  • NoRecordsTemplate handling
  • Search performance optimization
📄 阅读: references/filtering-and-search.md
  • 内置搜索框功能
  • 过滤类型选项(contains、startswith、endswith)
  • 结合服务端过滤的自定义过滤逻辑
  • 用于高级搜索UI的过滤模板
  • NoRecordsTemplate的处理
  • 搜索性能优化

Templates and Customization

模板与自定义

📄 Read: references/templates-and-customization.md
  • Item template customization
  • Value template (selected items display)
  • Header and footer templates
  • Group header templates
  • Icon integration in items
  • CSS styling and class customization
📄 阅读: references/templates-and-customization.md
  • 列表项模板自定义
  • 值模板(选中项展示)
  • 页眉和页脚模板
  • 分组页眉模板
  • 项中的图标集成
  • CSS样式和类自定义

Advanced Features

高级功能

📄 Read: references/advanced-features.md
  • Checkbox mode for enhanced multi-selection UI
  • Grouping items by category
  • Sorting options (ascending/descending)
  • Custom value support (create new values)
  • Chip customization and removal
  • Virtual scrolling for large datasets
  • Cascading MultiSelect patterns
📄 阅读: references/advanced-features.md
  • 用于增强多选UI的复选框模式
  • 按类别分组列表项
  • 排序选项(升序/降序)
  • 自定义值支持(创建新值)
  • 芯片自定义与移除
  • 大型数据集的虚拟滚动
  • 级联MultiSelect模式

Accessibility

无障碍支持

📄 Read: references/accessibility.md
  • WCAG 2.2 Level AA compliance
  • Keyboard navigation (Arrow keys, Tab, Enter, Escape)
  • ARIA attributes and roles
  • Screen reader support
  • Focus management best practices
  • Testing accessibility with tools
📄 阅读: references/accessibility.md
  • 符合WCAG 2.2 Level AA标准
  • 键盘导航(方向键、Tab、Enter、Escape)
  • ARIA属性和角色
  • 屏幕阅读器支持
  • 焦点管理最佳实践
  • 使用工具测试无障碍性

Quick Start Example

快速入门示例

Here's a minimal MultiSelect implementation:
razor
<!-- _ViewImports.cshtml -->
@addTagHelper *, Syncfusion.EJ2

<!-- View file -->
<ejs-multiselect id="multiselect" 
    dataSource="ViewBag.DataSource" 
    fields-text="Name" 
    fields-value="Id"
    placeholder="Select options">
</ejs-multiselect>
csharp
// Controller
public IActionResult Index()
{
    List<SelectData> data = new List<SelectData>
    {
        new SelectData { Id = "1", Name = "Option 1" },
        new SelectData { Id = "2", Name = "Option 2" },
        new SelectData { Id = "3", Name = "Option 3" }
    };
    ViewBag.DataSource = data;
    return View();
}
以下是一个极简的MultiSelect实现:
razor
<!-- _ViewImports.cshtml -->
@addTagHelper *, Syncfusion.EJ2

<!-- View file -->
<ejs-multiselect id="multiselect" 
    dataSource="ViewBag.DataSource" 
    fields-text="Name" 
    fields-value="Id"
    placeholder="Select options">
</ejs-multiselect>
csharp
// Controller
public IActionResult Index()
{
    List<SelectData> data = new List<SelectData>
    {
        new SelectData { Id = "1", Name = "Option 1" },
        new SelectData { Id = "2", Name = "Option 2" },
        new SelectData { Id = "3", Name = "Option 3" }
    };
    ViewBag.DataSource = data;
    return View();
}

Common Patterns

常见模式

Pattern 1: Simple String Array

模式1:简单字符串数组

Select from a list of string values:
razor
<ejs-multiselect id="skills" 
    dataSource="ViewBag.SkillsList" 
    placeholder="Select skills">
</ejs-multiselect>
从字符串值列表中选择:
razor
<ejs-multiselect id="skills" 
    dataSource="ViewBag.SkillsList" 
    placeholder="Select skills">
</ejs-multiselect>

Pattern 2: Object Array with Custom Display

模式2:自定义展示的对象数组

razor
<ejs-multiselect id="products" 
    dataSource="ViewBag.ProductList"
    fields-text="ProductName"
    fields-value="ProductId"
    placeholder="Select products">
</ejs-multiselect>
razor
<ejs-multiselect id="products" 
    dataSource="ViewBag.ProductList"
    fields-text="ProductName"
    fields-value="ProductId"
    placeholder="Select products">
</ejs-multiselect>

Pattern 3: With Checkboxes

模式3:带复选框的多选

razor
<ejs-multiselect id="languages" 
    dataSource="ViewBag.LanguageList"
    fields-text="Language"
    fields-value="LanguageCode"
    mode="CheckBox"
    placeholder="Select languages">
</ejs-multiselect>
razor
<ejs-multiselect id="languages" 
    dataSource="ViewBag.LanguageList"
    fields-text="Language"
    fields-value="LanguageCode"
    mode="CheckBox"
    placeholder="Select languages">
</ejs-multiselect>

Pattern 4: Filtered Selection

模式4:带过滤的选择

razor
<ejs-multiselect id="countries" 
    dataSource="ViewBag.CountryList"
    fields-text="CountryName"
    fields-value="CountryCode"
    allowFiltering="true"
    filterType="Contains"
    placeholder="Search and select countries">
</ejs-multiselect>
razor
<ejs-multiselect id="countries" 
    dataSource="ViewBag.CountryList"
    fields-text="CountryName"
    fields-value="CountryCode"
    allowFiltering="true"
    filterType="Contains"
    placeholder="Search and select countries">
</ejs-multiselect>

Key Properties Reference

核心属性参考

PropertyTypeDescription
dataSource
ArrayList of data items
fields-text
stringField name for display text
fields-value
stringField name for data value
placeholder
stringHint text when empty
value
string[]Initially selected values
allowFiltering
booleanEnable search/filter box
filterType
stringFilter type (StartsWith, Contains, EndsWith)
mode
stringSelection mode (Default, CheckBox, Delimiter)
readonly
booleanPrevent editing
disabled
booleanDisable the control
showSelectAll
booleanShow select all checkbox
maximumSelectionLength
numberMax selectable items
delayUpdateOn
stringEvent to trigger updates
fields-groupBy
stringGroup items by field
属性类型描述
dataSource
数组数据项列表
fields-text
字符串用于展示文本的字段名
fields-value
字符串用于数据值的字段名
placeholder
字符串空状态下的提示文本
value
字符串数组初始选中的值
allowFiltering
布尔值启用搜索/过滤框
filterType
字符串过滤类型(StartsWith、Contains、EndsWith)
mode
字符串选择模式(Default、CheckBox、Delimiter)
readonly
布尔值禁止编辑
disabled
布尔值禁用控件
showSelectAll
布尔值显示全选复选框
maximumSelectionLength
数字最大可选择项数量
delayUpdateOn
字符串触发更新的事件
fields-groupBy
字符串用于分组的字段名

Common Use Cases

常见使用场景

Use Case 1: Role Selection in Admin Panel

用例1:管理面板中的角色选择

Users select multiple roles to assign to administrators:
  • Display all available roles
  • Filter as user types
  • Show selections as chips
  • Validate selection count
用户选择多个角色分配给管理员:
  • 显示所有可用角色
  • 按用户输入过滤
  • 将选择项显示为芯片
  • 验证选择数量

Use Case 2: Product Category Filter

用例2:电商产品类别过滤

E-commerce site filtering products by multiple categories:
  • Group categories by parent
  • Show item count per category
  • Virtual scroll for 1000+ items
  • Remember selections
电商网站按多个类别过滤产品:
  • 按父类别分组
  • 显示每个类别的项数
  • 为1000+条数据启用虚拟滚动
  • 记住用户选择

Use Case 3: Team Member Assignment

用例3:团队成员分配

Assign multiple team members to projects:
  • Search by name
  • Show department grouping
  • Display avatar in selection chips
  • Prevent self-assignment
为项目分配多个团队成员:
  • 按姓名搜索
  • 按部门分组展示
  • 在选择芯片中显示头像
  • 禁止自我分配

Use Case 4: Tag Selection

用例4:标签选择

Blog/content tagging with MultiSelect:
  • Allow custom tag creation
  • Show tag count/popularity
  • Group by category
  • Auto-complete suggestions
博客/内容的标签选择:
  • 允许创建自定义标签
  • 显示标签数量/热度
  • 按类别分组
  • 自动补全建议

Best Practices

最佳实践

  1. Always provide clear labels - Label the MultiSelect with associated
    <label>
    element
  2. Set reasonable default selections - Pre-select logical defaults when appropriate
  3. Use filtering for large lists - Enable filtering when >10 items
  4. Validate on server - Never trust client-side validation alone
  5. Handle empty state - Provide clear message when no items selected
  6. Group related items - Use groupBy for lists >20 items
  7. Limit selection count - Use maximumSelectionLength to prevent abuse
  8. Test keyboard navigation - Ensure all features accessible via keyboard
  9. Provide accessible labels - Use proper ARIA attributes
  10. Monitor performance - Virtual scroll for 1000+ items
  1. 始终提供清晰的标签 - 使用关联的
    <label>
    元素标记MultiSelect
  2. 设置合理的默认选择 - 适当时预选择符合逻辑的默认值
  3. 为大型列表启用过滤 - 当选项数量>10时启用过滤
  4. 在服务端验证 - 永远不要只依赖客户端验证
  5. 处理空状态 - 当没有选中项时提供清晰的提示信息
  6. 对相关项进行分组 - 当列表项>20时使用groupBy
  7. 限制选择数量 - 使用maximumSelectionLength防止滥用
  8. 测试键盘导航 - 确保所有功能都可通过键盘访问
  9. 提供无障碍标签 - 使用正确的ARIA属性
  10. 监控性能 - 为1000+条数据启用虚拟滚动

Next Steps

后续步骤

  1. Start with Getting Started - Follow setup instructions
  2. Implement a simple example - Create basic MultiSelect binding
  3. Add filtering - Enable search functionality
  4. Customize templates - Enhance appearance with templates
  5. Handle selection events - Respond to user selections
  6. Test accessibility - Verify keyboard and screen reader support

Ready to learn? Start with Getting Started
  1. 从入门指南开始 - 按照设置说明操作
  2. 实现一个简单示例 - 创建基础的MultiSelect绑定
  3. 添加过滤功能 - 启用搜索功能
  4. 自定义模板 - 使用模板增强外观
  5. 处理选择事件 - 响应用户选择
  6. 测试无障碍性 - 验证键盘和屏幕阅读器支持

准备好学习了?入门指南开始 →