syncfusion-aspnetcore-chat-ui
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSyncfusion ASP.NET Core Chat-UI Control
Syncfusion ASP.NET Core Chat-UI 控件
Overview
概述
The Chat-UI component provides a complete conversational interface with real-time messaging, file attachments, user presence, and extensive customization options. This skill guides you through implementing chat interfaces for customer support, team collaboration, and interactive applications using ASP.NET Core tag helpers and Razor pages.
The Chat-UI component is an interactive messaging interface featuring:
- Rich Message Support: Text content, pinned messages, threaded replies, message forwarding
- User Management: Multi-user conversations, presence status, user configuration
- File Attachments: Upload, preview, download with file type/size restrictions
- Event System: Created, message send, user typing, attachment events
- Templates: Customizable UI for empty chat, messages, typing indicator, suggestions, footer
- Appearance: Configurable placeholder, width, height, CSS classes
- Timestamps: Show/hide timestamps with customizable format
- Advanced Features: Compact mode, globalization, RTL support, speech-to-text
Chat-UI组件提供了一个完整的对话界面,具备实时消息、文件附件、用户在线状态以及丰富的自定义选项。本技能将指导你使用ASP.NET Core标签助手和Razor页面,为客户支持、团队协作和交互式应用实现聊天界面。
Chat-UI组件是一个交互式消息界面,具备以下特性:
- 丰富消息支持: 文本内容、置顶消息、线程回复、消息转发
- 用户管理: 多用户对话、在线状态、用户配置
- 文件附件: 上传、预览、下载,支持文件类型/大小限制
- 事件系统: 创建、消息发送、用户输入、附件相关事件
- 模板: 空聊天、消息、输入指示器、建议、页脚的可自定义UI
- 外观: 可配置占位符、宽度、高度、CSS类
- 时间戳: 显示/隐藏时间戳,支持自定义格式
- 高级功能: 紧凑模式、全球化、RTL支持、语音转文字
Quick Start Example
快速开始示例
razor
@using Syncfusion.EJ2.InteractiveChat;
<div style="height:400px; width:450px">
<ejs-chatui id="chatUI">
<e-chatui-user id="user1" user="Albert"></e-chatui-user>
<e-chatui-messages>
@foreach (var message in ViewBag.ChatMessagesData)
{
<e-chatui-message text="@message.Text" author="@message.Author"></e-chatui-message>
}
</e-chatui-messages>
</ejs-chatui>
</div>Corresponding C# Controller:
csharp
using Syncfusion.EJ2.InteractiveChat;
public ActionResult Default()
{
var currentUser = new ChatUIUser() { Id = "user1", User = "Albert" };
var otherUser = new ChatUIUser() { Id = "user2", User = "Michale Suyama" };
var messages = new List<ChatUIMessage>()
{
new ChatUIMessage() { Text = "Hi Michale, are we on track?", Author = currentUser },
new ChatUIMessage() { Text = "Yes, all set!", Author = otherUser }
};
ViewBag.ChatMessagesData = messages;
return View();
}razor
@using Syncfusion.EJ2.InteractiveChat;
<div style="height:400px; width:450px">
<ejs-chatui id="chatUI">
<e-chatui-user id="user1" user="Albert"></e-chatui-user>
<e-chatui-messages>
@foreach (var message in ViewBag.ChatMessagesData)
{
<e-chatui-message text="@message.Text" author="@message.Author"></e-chatui-message>
}
</e-chatui-messages>
</ejs-chatui>
</div>对应的C#控制器:
csharp
using Syncfusion.EJ2.InteractiveChat;
public ActionResult Default()
{
var currentUser = new ChatUIUser() { Id = "user1", User = "Albert" };
var otherUser = new ChatUIUser() { Id = "user2", User = "Michale Suyama" };
var messages = new List<ChatUIMessage>()
{
new ChatUIMessage() { Text = "Hi Michale, are we on track?", Author = currentUser },
new ChatUIMessage() { Text = "Yes, all set!", Author = otherUser }
};
ViewBag.ChatMessagesData = messages;
return View();
}Documentation Navigation
文档导航
Getting Started
入门指南
📄 Read: references/getting-started.md
- NuGet package installation and dependencies
- ASP.NET Core project setup with Razor pages
- Tag helper registration and configuration
- CDN stylesheet and script setup
- Script manager registration
- Basic Chat-UI implementation
- Initial user and message configuration
📄 阅读: references/getting-started.md
- NuGet包安装及依赖项
- 基于Razor页面的ASP.NET Core项目设置
- 标签助手注册与配置
- CDN样式表和脚本设置
- 脚本管理器注册
- 基础Chat-UI实现
- 初始用户与消息配置
Message Configuration
消息配置
📄 Read: references/messages-configuration.md
- Message model setup and properties
- Adding and managing text messages
- Message configuration (ID, text, author, timestamp)
- Pinned messages for important conversations
- Reply-to for threaded conversations
- Forwarded messages and message tracking
- Compact mode for streamlined layouts
📄 阅读: references/messages-configuration.md
- 消息模型设置及属性
- 文本消息的添加与管理
- 消息配置(ID、文本、作者、时间戳)
- 重要对话的置顶消息
- 线程对话的回复功能
- 转发消息与消息追踪
- 精简布局的紧凑模式
User Configuration
用户配置
📄 Read: references/user-configuration.md
- ChatUIUser model setup and properties
- User identity configuration
- Setting current user context
- Multi-user support and management
- User presence and status indicators
- Avatar configuration and styling
📄 阅读: references/user-configuration.md
- ChatUIUser模型设置及属性
- 用户身份配置
- 当前用户上下文设置
- 多用户支持与管理
- 用户在线状态指示器
- 头像配置与样式
Appearance & Styling
外观与样式
📄 Read: references/appearance-styling.md
- Placeholder text customization
- Width and height configuration
- CSS class application and customization
- Component-level styling
- Theme customization approaches
- Responsive design patterns
📄 阅读: references/appearance-styling.md
- 占位符文本自定义
- 宽度与高度配置
- CSS类的应用与自定义
- 组件级样式设置
- 主题自定义方法
- 响应式设计模式
Events & Interactions
事件与交互
📄 Read: references/events-interactions.md
- Created event for initialization
- Message send event handling
- User typing event detection
- Attachment upload events (before, success, failure)
- Attachment removal and click events
- Event binding patterns and best practices
📄 阅读: references/events-interactions.md
- 初始化时的Created事件
- 消息发送事件处理
- 用户输入事件检测
- 附件上传事件(上传前、成功、失败)
- 附件移除与点击事件
- 事件绑定模式与最佳实践
Methods & API
方法与API
📄 Read: references/methods-api.md
- addMessage method for programmatic message addition
- updateMessage method for editing existing messages
- scrollToBottom method for view navigation
- Real-time integration with SignalR
- Best practices for performance and error handling
📄 阅读: references/methods-api.md
- 用于程序化添加消息的addMessage方法
- 用于编辑现有消息的updateMessage方法
- 用于视图导航的scrollToBottom方法
- 与SignalR的实时集成
- 性能与错误处理的最佳实践
Templates & Customization
模板与自定义
📄 Read: references/templates-customization.md
- Empty chat template for initial states
- Message custom templates with jsrender
- Time break template for message organization
- Typing indicator template customization
- Suggestion template for auto-complete
- Footer template for custom input areas
- Advanced template patterns and styling
📄 阅读: references/templates-customization.md
- 初始状态的空聊天模板
- 基于jsrender的消息自定义模板
- 消息组织的时间间隔模板
- 输入指示器模板自定义
- 自动补全的建议模板
- 自定义输入区域的页脚模板
- 高级模板模式与样式
File Attachments
文件附件
📄 Read: references/file-attachments.md
- Enable attachment support with enableAttachments
- Configure attachment settings
- Save and remove URL endpoints
- File type restrictions (allowedFileTypes)
- File size limits (maxFileSize)
- Save format options (Blob vs Base64)
- Drag-and-drop support configuration
- Server path and upload handling
📄 阅读: references/file-attachments.md
- 通过enableAttachments启用附件支持
- 配置附件设置
- 保存与移除URL端点
- 文件类型限制(allowedFileTypes)
- 文件大小限制(maxFileSize)
- 保存格式选项(Blob vs Base64)
- 拖拽支持配置
- 服务器路径与上传处理
Header & Footer
页眉与页脚
📄 Read: references/header-footer.md
- Show/hide header with showHeader property
- Header text configuration and display
- Header icon styling with headerIconCss
- Show/hide footer with showFooter property
- Footer template customization
- Input area configuration
📄 阅读: references/header-footer.md
- 通过showHeader属性显示/隐藏页眉
- 页眉文本配置与显示
- 通过headerIconCss设置页眉图标样式
- 通过showFooter属性显示/隐藏页脚
- 页脚模板自定义
- 输入区域配置
Timestamps & Time Breaks
时间戳与时间间隔
📄 Read: references/timestamps-timebreaks.md
- Show/hide timestamps with showTimeStamp
- Timestamp format customization (timeStampFormat)
- Time break separators for message organization
- Date-wise message grouping
- Timestamp template patterns
📄 阅读: references/timestamps-timebreaks.md
- 通过showTimeStamp显示/隐藏时间戳
- 时间戳格式自定义(timeStampFormat)
- 消息组织的时间间隔分隔符
- 按日期分组消息
- 时间戳模板模式
Typing Indicators
输入指示器
📄 Read: references/typing-indicator.md
- Show/hide typing indicator
- Multi-user typing display
- Typing indicator template customization
- User presence detection
- Styling typing indicator UI
📄 阅读: references/typing-indicator.md
- 显示/隐藏输入指示器
- 多用户输入显示
- 输入指示器模板自定义
- 用户在线状态检测
- 输入指示器UI样式
Mentions & User References
提及与用户引用
📄 Read: references/mentions-integration.md
- Configure mentionable users
- Mention trigger character customization
- Predefined mentions in messages
- Mention selection and events
- Mention item template and styling
📄 阅读: references/mentions-integration.md
- 配置可提及用户
- 提及触发字符自定义
- 消息中的预定义提及
- 提及选择与事件
- 提及项模板与样式
Globalization & RTL
全球化与RTL
📄 Read: references/globalization-rtl.md
- Localization and multi-language support
- Setting culture and locale
- RTL (Right-to-Left) layout support
- Language-specific templates
- Speech-to-text localization
📄 阅读: references/globalization-rtl.md
- 本地化与多语言支持
- 设置文化与区域
- RTL(从右到左)布局支持
- 特定语言模板
- 语音转文字本地化
Toolbar Configuration
工具栏配置
📄 Read: references/toolbar-configuration.md
- Header toolbar configuration and items
- Message toolbar settings and customization
- Toolbar item configuration and events
- Custom toolbar actions and handlers
- Toolbar visibility and styling
📄 阅读: references/toolbar-configuration.md
- 页眉工具栏配置与项设置
- 消息工具栏设置与自定义
- 工具栏项配置与事件
- 自定义工具栏操作与处理程序
- 工具栏可见性与样式
Advanced Features
高级功能
📄 Read: references/advanced-features.md
- Load on demand with scroll handling
- Auto-scroll to bottom behavior
- Enable persistence for state management
- Performance optimization techniques
- Server-side data loading strategies
📄 阅读: references/advanced-features.md
- 结合滚动处理的按需加载
- 自动滚动到底部的行为
- 启用状态管理的持久化
- 性能优化技巧
- 服务器端数据加载策略
Suggestions Feature
建议功能
📄 Read: references/suggestions-feature.md
- Enable suggestions with suggestions property
- Suggestion template customization
- Context-based suggestion filtering
- Suggestion selection and handling
- Custom suggestion UI and styling
📄 阅读: references/suggestions-feature.md
- 通过suggestions属性启用建议
- 建议模板自定义
- 基于上下文的建议过滤
- 建议选择与处理
- 自定义建议UI与样式
Common Patterns
常见模式
Create a Basic Chat Interface
创建基础聊天界面
razor
<div style="height:400px; width:500px">
<ejs-chatui id="chatUI"
placeholder="Type a message..."
showHeader="true"
headerText="Support Chat">
<e-chatui-user id="user1" user="Support Agent"></e-chatui-user>
</ejs-chatui>
</div>razor
<div style="height:400px; width:500px">
<ejs-chatui id="chatUI"
placeholder="Type a message..."
showHeader="true"
headerText="Support Chat">
<e-chatui-user id="user1" user="Support Agent"></e-chatui-user>
</ejs-chatui>
</div>Add Messages with Events
添加带事件的消息
razor
<ejs-chatui id="chatUI" messageSend="onMessageSend">
<e-chatui-user id="user1" user="Albert"></e-chatui-user>
<e-chatui-messages>
@foreach (var message in ViewBag.ChatMessagesData)
{
<e-chatui-message text="@message.Text"
author="@message.Author"
timeStamp="@message.TimeStamp"></e-chatui-message>
}
</e-chatui-messages>
</ejs-chatui>
<script>
function onMessageSend(args) {
// Handle message send event
console.log("Message sent:", args);
}
</script>razor
<ejs-chatui id="chatUI" messageSend="onMessageSend">
<e-chatui-user id="user1" user="Albert"></e-chatui-user>
<e-chatui-messages>
@foreach (var message in ViewBag.ChatMessagesData)
{
<e-chatui-message text="@message.Text"
author="@message.Author"
timeStamp="@message.TimeStamp"></e-chatui-message>
}
</e-chatui-messages>
</ejs-chatui>
<script>
function onMessageSend(args) {
// Handle message send event
console.log("Message sent:", args);
}
</script>Enable File Attachments
启用文件附件
razor
<ejs-chatui id="chatUI" enableAttachments="true">
<e-chatui-user id="user1" user="Albert"></e-chatui-user>
<e-chatui-attachmentsettings
saveUrl=@Url.Content("https://services.syncfusion.com/aspnet/production/api/FileUploader/Save")
removeUrl=@Url.Content("https://services.syncfusion.com/aspnet/production/api/FileUploader/Remove")
maxFileSize="5000000"
allowedFileTypes=".pdf,.docx,.xlsx">
</e-chatui-attachmentsettings>
</ejs-chatui>razor
<ejs-chatui id="chatUI" enableAttachments="true">
<e-chatui-user id="user1" user="Albert"></e-chatui-user>
<e-chatui-attachmentsettings
saveUrl=@Url.Content("https://services.syncfusion.com/aspnet/production/api/FileUploader/Save")
removeUrl=@Url.Content("https://services.syncfusion.com/aspnet/production/api/FileUploader/Remove")
maxFileSize="5000000"
allowedFileTypes=".pdf,.docx,.xlsx">
</e-chatui-attachmentsettings>
</ejs-chatui>Key Properties
关键属性
| Property | Type | Purpose |
|---|---|---|
| string | Unique identifier for the ChatUI component |
| string | Input field hint text (default: "Type your message…") |
| string | Chat UI width (default: 100%) |
| string | Chat UI height (default: 100%) |
| boolean | Display header section (default: true) |
| string | Header title/name display |
| object | Configure toolbar items in header |
| boolean | Display input footer (default: true) |
| boolean | Display message timestamps (default: true) |
| string | Timestamp format pattern (default: "dd/MM/yyyy hh:mm a") |
| string | CSS classes for styling |
| boolean | Enable file upload support (default: false) |
| boolean | Align all messages left (default: false) |
| boolean | Enable lazy loading of messages (default: false) |
| boolean | Automatically scroll to latest message (default: true) |
| boolean | Persist chat state across sessions (default: false) |
| array | Quick reply suggestions for users |
| object | Configure message-level toolbar actions |
| 属性 | 类型 | 用途 |
|---|---|---|
| string | ChatUI组件的唯一标识符 |
| string | 输入框提示文本(默认:"Type your message…") |
| string | 聊天UI宽度(默认:100%) |
| string | 聊天UI高度(默认:100%) |
| boolean | 显示页眉区域(默认:true) |
| string | 页眉标题/名称显示 |
| object | 配置页眉中的工具栏项 |
| boolean | 显示输入页脚(默认:true) |
| boolean | 显示消息时间戳(默认:true) |
| string | 时间戳格式模式(默认:"dd/MM/yyyy hh:mm a") |
| string | 用于样式的CSS类 |
| boolean | 启用文件上传支持(默认:false) |
| boolean | 所有消息左对齐(默认:false) |
| boolean | 启用消息懒加载(默认:false) |
| boolean | 自动滚动到最新消息(默认:true) |
| boolean | 在会话间持久化聊天状态(默认:false) |
| array | 给用户的快速回复建议 |
| object | 配置消息级工具栏操作 |
Common Use Cases
常见用例
Use Case 1: Customer Support Chat
- Multiple support agents handling customer queries
- File attachment for screenshots/documents
- Message history with timestamps
- Typing indicators to show agent engagement
- Header with support agent name and status
Use Case 2: Team Collaboration
- Mention team members with @ mentions
- Pin important discussion points
- Forward messages for reference
- Message editing and deletion
- Multi-user presence indicators
Use Case 3: Multilingual Support
- RTL support for Arabic/Hebrew languages
- Localized UI strings via globalization
- Culture-specific timestamp formats
- Support for multiple character sets
用例1:客户支持聊天
- 多个支持代理处理客户查询
- 支持截图/文档的文件附件
- 带时间戳的消息历史
- 显示代理忙碌状态的输入指示器
- 包含支持代理名称和状态的页眉
用例2:团队协作
- 使用@提及团队成员
- 置顶重要讨论点
- 转发消息供参考
- 消息编辑与删除
- 多用户在线状态指示器
用例3:多语言支持
- 阿拉伯语/希伯来语的RTL支持
- 通过全球化实现本地化UI字符串
- 特定文化的时间戳格式
- 支持多种字符集