syncfusion-aspnetcore-multiselect
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImplementing 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
核心功能
| Feature | Use Case |
|---|---|
| Multiple Selection | Select multiple values from dropdown list |
| Filtering & Search | Search through large lists efficiently |
| Checkboxes | Visual indication of multi-select with checkbox mode |
| Data Binding | Local arrays or remote data sources |
| Templates | Customize item appearance and selected value display |
| Grouping | Organize options into logical categories |
| Sorting | Alphabetically sort options (ascending/descending) |
| Chip Display | Show selected items as removable chips |
| Custom Values | Allow users to add custom selection values |
| Virtual Scrolling | Efficiently handle 1000+ item lists |
| Cascading | Link multiple MultiSelect components |
| WCAG Compliance | Built-in accessibility for screen readers, keyboard nav |
| Events | Respond 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
核心属性参考
| Property | Type | Description |
|---|---|---|
| Array | List of data items |
| string | Field name for display text |
| string | Field name for data value |
| string | Hint text when empty |
| string[] | Initially selected values |
| boolean | Enable search/filter box |
| string | Filter type (StartsWith, Contains, EndsWith) |
| string | Selection mode (Default, CheckBox, Delimiter) |
| boolean | Prevent editing |
| boolean | Disable the control |
| boolean | Show select all checkbox |
| number | Max selectable items |
| string | Event to trigger updates |
| string | Group items by field |
| 属性 | 类型 | 描述 |
|---|---|---|
| 数组 | 数据项列表 |
| 字符串 | 用于展示文本的字段名 |
| 字符串 | 用于数据值的字段名 |
| 字符串 | 空状态下的提示文本 |
| 字符串数组 | 初始选中的值 |
| 布尔值 | 启用搜索/过滤框 |
| 字符串 | 过滤类型(StartsWith、Contains、EndsWith) |
| 字符串 | 选择模式(Default、CheckBox、Delimiter) |
| 布尔值 | 禁止编辑 |
| 布尔值 | 禁用控件 |
| 布尔值 | 显示全选复选框 |
| 数字 | 最大可选择项数量 |
| 字符串 | 触发更新的事件 |
| 字符串 | 用于分组的字段名 |
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
最佳实践
- Always provide clear labels - Label the MultiSelect with associated element
<label> - Set reasonable default selections - Pre-select logical defaults when appropriate
- Use filtering for large lists - Enable filtering when >10 items
- Validate on server - Never trust client-side validation alone
- Handle empty state - Provide clear message when no items selected
- Group related items - Use groupBy for lists >20 items
- Limit selection count - Use maximumSelectionLength to prevent abuse
- Test keyboard navigation - Ensure all features accessible via keyboard
- Provide accessible labels - Use proper ARIA attributes
- Monitor performance - Virtual scroll for 1000+ items
- 始终提供清晰的标签 - 使用关联的元素标记MultiSelect
<label> - 设置合理的默认选择 - 适当时预选择符合逻辑的默认值
- 为大型列表启用过滤 - 当选项数量>10时启用过滤
- 在服务端验证 - 永远不要只依赖客户端验证
- 处理空状态 - 当没有选中项时提供清晰的提示信息
- 对相关项进行分组 - 当列表项>20时使用groupBy
- 限制选择数量 - 使用maximumSelectionLength防止滥用
- 测试键盘导航 - 确保所有功能都可通过键盘访问
- 提供无障碍标签 - 使用正确的ARIA属性
- 监控性能 - 为1000+条数据启用虚拟滚动
Next Steps
后续步骤
- Start with Getting Started - Follow setup instructions
- Implement a simple example - Create basic MultiSelect binding
- Add filtering - Enable search functionality
- Customize templates - Enhance appearance with templates
- Handle selection events - Respond to user selections
- Test accessibility - Verify keyboard and screen reader support
Ready to learn? Start with Getting Started →
- 从入门指南开始 - 按照设置说明操作
- 实现一个简单示例 - 创建基础的MultiSelect绑定
- 添加过滤功能 - 启用搜索功能
- 自定义模板 - 使用模板增强外观
- 处理选择事件 - 响应用户选择
- 测试无障碍性 - 验证键盘和屏幕阅读器支持
准备好学习了? 从入门指南开始 →