Syncfusion ASP.NET MVC Chat UI
The Syncfusion ASP.NET MVC Chat UI (Syncfusion.EJ2.InteractiveChat.ChatUI) is a feature-rich conversational interface component for building real-time chat applications, AI assistants, and bot integrations. It supports structured messages, user avatars, typing indicators, file attachments, mention tagging, markdown rendering, and extensive template customization.
Navigation Guide
Getting Started
📄 Read: references/getting-started.md
- NuGet package installation (
Syncfusion.EJ2.MVC5)
- Namespace, stylesheet, and script references
- Script manager registration
- Basic Chat UI rendering with
@Html.EJS().ChatUI()
- Configuring initial messages and current user
Messages
📄 Read: references/messages.md
ChatUIMessage model: Text, Id, Author, Timestamp, Status, AttachedFile
- Pinned messages, reply-to threading (
ChatUIReplyTo with Timestamp, TimestampFormat, MentionUsers), forwarded messages
- Compact mode, auto-scroll, quick reply suggestions
- Message toolbar with
MessageToolbarItemClickedEventArgs (item, message, cancel, event)
- Message status:
IconCss, Text, Tooltip usage
- Markdown content rendering with
marked + DOMPurify
User Configuration
📄 Read: references/user-configuration.md
ChatUIUser model: Id, User, AvatarUrl, AvatarBgColor, CssClass, StatusIconCss
- Defining the current user with the
User property
- Avatar images, fallback initials, background color
- Presence status icons (online, offline, busy, away)
Header and Toolbar
📄 Read: references/header-and-toolbar.md
- Show/hide header (
ShowHeader), header text and icon
ChatUIToolbarSettings — header toolbar items
- Toolbar item properties:
IconCss, Type, Text, Visible, Disabled, Tooltip, CssClass, Align, TabIndex, Template
ItemClicked event handler
Footer and Templates
📄 Read: references/footer-and-templates.md
- Show/hide footer (
ShowFooter), custom footer template
- Empty chat template, message template, suggestion template
- Typing users template, time break template
- Template context variables (
message, index, users, messageDate, suggestion)
Events and Methods
📄 Read: references/events-and-methods.md
Created, MessageSend, UserTyping events with full event args (cancel, isTyping, message, user, itemData)
addMessage() — add message as string or object
updateMessage() — edit an existing message by ID
scrollToBottom() — programmatic scroll to latest message
scrollToMessage(messageId) — scroll to a specific message by ID
focus() — programmatically focus the chat input textarea
- Accessing the ChatUI instance via
ej.base.getInstance()
Appearance and Layout
📄 Read: references/appearance-and-layout.md
- Placeholder,
Width, Height, CssClass
- Timestamps (
ShowTimeStamp, TimeStampFormat)
- Time breaks (
ShowTimeBreak, TimeBreakTemplate)
- Typing indicator (
TypingUsers)
- Load on demand (
LoadOnDemand) for long conversation histories
- Persistence (
EnablePersistence) — save and restore state across page reloads
File Attachments
📄 Read: references/file-attachments.md
- Enable file attachments (
EnableAttachments)
AttachmentSettings: SaveUrl, RemoveUrl, AllowedFileTypes, MaxFileSize, SaveFormat, Path
- Drag-and-drop, maximum file count
- Custom attachment and preview templates
- Pre-populating attachments on messages at initial render (
AttachedFile)
- Attachment lifecycle events and
ChatAttachmentClickEventArgs (file, cancel, event)
Mentions and Globalization
📄 Read: references/mentions-and-globalization.md
MentionUsers list, @ mention trigger popup
- Custom trigger character (
MentionTriggerChar)
- Predefined mentions in message text using
{0}, {1} placeholders
MentionSelect event
- Localization (
Locale, ej.base.L10n.load) and RTL (EnableRtl)
Bot Integrations and Speech-to-Text
📄 Read: references/bot-integrations.md
- Microsoft Bot Framework (Direct Line) integration
- Google Dialogflow integration
- Speech-to-Text via Web Speech API +
SpeechToText component
- Secure token server pattern
MessageSend + addMessage() integration pattern
- Troubleshooting common bot connection issues
Quick Start Example
Controller (HomeController.cs):
using Syncfusion.EJ2.InteractiveChat;
public ActionResult Index()
{
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 for the deadline?", Author = currentUser },
new ChatUIMessage { Text = "Yes, the design phase is complete.", Author = otherUser },
new ChatUIMessage { Text = "I'll review it and send feedback by today.", Author = currentUser }
};
ViewBag.CurrentUser = currentUser;
ViewBag.Messages = messages;
return View();
}
View (Index.cshtml):
@using Syncfusion.EJ2.InteractiveChat
<div style="height:400px; width:450px;">
@Html.EJS().ChatUI("chatUI")
.User(ViewBag.CurrentUser)
.Messages(ViewBag.Messages)
.HeaderText("Team Chat")
.Render()
</div>
Required layout references (_Layout.cshtml):
<head>
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/{{ site.ej2version }}/fluent.css" />
<script src="https://cdn.syncfusion.com/ej2/{{ site.ej2version }}/dist/ej2.min.js"></script>
</head>
<body>
...
@Html.EJS().ScriptManager()
</body>
Common Patterns
Programmatically Add a Message (Bot Reply)
function onMessageSend(args) {
var chatUI = ej.base.getInstance(document.getElementById('chatUI'), ejs.interactivechat.ChatUI);
fetch('/api/bot/reply', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text: args.message.text })
})
.then(r => r.json())
.then(data => chatUI.addMessage({ text: data.reply, author: botUser }));
}
Enable File Attachments
@Html.EJS().ChatUI("chatUI")
.User(ViewBag.CurrentUser)
.EnableAttachments(true)
.AttachmentSettings(new ChatUIFileAttachmentSettings {
SaveUrl = Url.Content("https://services.syncfusion.com/aspnet/production/api/FileUploader/Save"),
RemoveUrl = Url.Content("https://services.syncfusion.com/aspnet/production/api/FileUploader/Remove")
})
.Render()
Show Typing Indicator (Client-Side)
function onCreated() {
var chatUI = ej.base.getInstance(document.getElementById('chatUI'), ejs.interactivechat.ChatUI);
chatUI.typingUsers = [{ id: "user2", user: "Michale Suyama" }];
chatUI.dataBind();
}
Key Properties Reference
| Property |
Type |
Default |
Description |
User |
ChatUIUser |
— |
Current logged-in user |
Messages |
List<ChatUIMessage> |
[] |
Initial message collection |
HeaderText |
string |
— |
Text shown in header |
HeaderIconCss |
string |
— |
CSS class for header icon |
ShowHeader |
bool |
true |
Show or hide the header |
ShowFooter |
bool |
true |
Show or hide the footer |
Placeholder |
string |
"Type your message…" |
Textarea placeholder |
Width |
string |
"100%" |
Component width |
Height |
string |
"100%" |
Component height |
CssClass |
string |
— |
Custom CSS class |
AutoScrollToBottom |
bool |
false |
Auto-scroll on new message |
ShowTimeStamp |
bool |
true |
Show message timestamps |
TimeStampFormat |
string |
"dd/MM/yyyy hh:mm a" |
Global timestamp format |
ShowTimeBreak |
bool |
false |
Show date separators |
EnableCompactMode |
bool |
false |
Align all messages left |
LoadOnDemand |
bool |
false |
Lazy-load messages on scroll |
EnablePersistence |
bool |
false |
Persist state across page reloads via localStorage |
EnableAttachments |
bool |
false |
Enable file attachments |
MentionUsers |
List<ChatUIUser> |
— |
Users available for @ mention |
TypingUsers |
List<ChatUIUser> |
— |
Users currently typing |
EnableRtl |
bool |
false |
Right-to-left layout |
Locale |
string |
"en" |
Localization culture code |
1---2name: syncfusion-aspnetmvc-chat-ui3description: Implement a real-time Chat UI with Syncfusion ASP.NET MVC ChatUI component. Use when building chat interfaces, messaging apps, bot integrations, or interactive conversations. Covers messages, header/footer, templates, events, methods, file attachments, typing indicators, mentions, globalization, speech-to-text, and bot integrations.4---56# Syncfusion ASP.NET MVC Chat UI78The Syncfusion ASP.NET MVC Chat UI (`Syncfusion.EJ2.InteractiveChat.ChatUI`) is a feature-rich conversational interface component for building real-time chat applications, AI assistants, and bot integrations. It supports structured messages, user avatars, typing indicators, file attachments, mention tagging, markdown rendering, and extensive template customization.910## Navigation Guide1112### Getting Started13📄 **Read:** [references/getting-started.md](references/getting-started.md)14- NuGet package installation (`Syncfusion.EJ2.MVC5`)15- Namespace, stylesheet, and script references16- Script manager registration17- Basic Chat UI rendering with `@Html.EJS().ChatUI()`18- Configuring initial messages and current user1920### Messages21📄 **Read:** [references/messages.md](references/messages.md)22- `ChatUIMessage` model: `Text`, `Id`, `Author`, `Timestamp`, `Status`, `AttachedFile`23- Pinned messages, reply-to threading (`ChatUIReplyTo` with `Timestamp`, `TimestampFormat`, `MentionUsers`), forwarded messages24- Compact mode, auto-scroll, quick reply suggestions25- Message toolbar with `MessageToolbarItemClickedEventArgs` (`item`, `message`, `cancel`, `event`)26- Message status: `IconCss`, `Text`, `Tooltip` usage27- Markdown content rendering with `marked` + `DOMPurify`2829### User Configuration30📄 **Read:** [references/user-configuration.md](references/user-configuration.md)31- `ChatUIUser` model: `Id`, `User`, `AvatarUrl`, `AvatarBgColor`, `CssClass`, `StatusIconCss`32- Defining the current user with the `User` property33- Avatar images, fallback initials, background color34- Presence status icons (online, offline, busy, away)3536### Header and Toolbar37📄 **Read:** [references/header-and-toolbar.md](references/header-and-toolbar.md)38- Show/hide header (`ShowHeader`), header text and icon39- `ChatUIToolbarSettings` — header toolbar items40- Toolbar item properties: `IconCss`, `Type`, `Text`, `Visible`, `Disabled`, `Tooltip`, `CssClass`, `Align`, `TabIndex`, `Template`41- `ItemClicked` event handler4243### Footer and Templates44📄 **Read:** [references/footer-and-templates.md](references/footer-and-templates.md)45- Show/hide footer (`ShowFooter`), custom footer template46- Empty chat template, message template, suggestion template47- Typing users template, time break template48- Template context variables (`message`, `index`, `users`, `messageDate`, `suggestion`)4950### Events and Methods51📄 **Read:** [references/events-and-methods.md](references/events-and-methods.md)52- `Created`, `MessageSend`, `UserTyping` events with full event args (`cancel`, `isTyping`, `message`, `user`, `itemData`)53- `addMessage()` — add message as string or object54- `updateMessage()` — edit an existing message by ID55- `scrollToBottom()` — programmatic scroll to latest message56- `scrollToMessage(messageId)` — scroll to a specific message by ID57- `focus()` — programmatically focus the chat input textarea58- Accessing the ChatUI instance via `ej.base.getInstance()`5960### Appearance and Layout61📄 **Read:** [references/appearance-and-layout.md](references/appearance-and-layout.md)62- Placeholder, `Width`, `Height`, `CssClass`63- Timestamps (`ShowTimeStamp`, `TimeStampFormat`)64- Time breaks (`ShowTimeBreak`, `TimeBreakTemplate`)65- Typing indicator (`TypingUsers`)66- Load on demand (`LoadOnDemand`) for long conversation histories67- Persistence (`EnablePersistence`) — save and restore state across page reloads6869### File Attachments70📄 **Read:** [references/file-attachments.md](references/file-attachments.md)71- Enable file attachments (`EnableAttachments`)72- `AttachmentSettings`: `SaveUrl`, `RemoveUrl`, `AllowedFileTypes`, `MaxFileSize`, `SaveFormat`, `Path`73- Drag-and-drop, maximum file count74- Custom attachment and preview templates75- Pre-populating attachments on messages at initial render (`AttachedFile`)76- Attachment lifecycle events and `ChatAttachmentClickEventArgs` (`file`, `cancel`, `event`)7778### Mentions and Globalization79📄 **Read:** [references/mentions-and-globalization.md](references/mentions-and-globalization.md)80- `MentionUsers` list, `@` mention trigger popup81- Custom trigger character (`MentionTriggerChar`)82- Predefined mentions in message text using `{0}`, `{1}` placeholders83- `MentionSelect` event84- Localization (`Locale`, `ej.base.L10n.load`) and RTL (`EnableRtl`)8586### Bot Integrations and Speech-to-Text87📄 **Read:** [references/bot-integrations.md](references/bot-integrations.md)88- Microsoft Bot Framework (Direct Line) integration89- Google Dialogflow integration90- Speech-to-Text via Web Speech API + `SpeechToText` component91- Secure token server pattern92- `MessageSend` + `addMessage()` integration pattern93- Troubleshooting common bot connection issues9495---9697## Quick Start Example9899**Controller (`HomeController.cs`):**100```csharp101using Syncfusion.EJ2.InteractiveChat;102103public ActionResult Index()104{105 var currentUser = new ChatUIUser { Id = "user1", User = "Albert" };106 var otherUser = new ChatUIUser { Id = "user2", User = "Michale Suyama" };107108 var messages = new List<ChatUIMessage>109 {110 new ChatUIMessage { Text = "Hi Michale, are we on track for the deadline?", Author = currentUser },111 new ChatUIMessage { Text = "Yes, the design phase is complete.", Author = otherUser },112 new ChatUIMessage { Text = "I'll review it and send feedback by today.", Author = currentUser }113 };114115 ViewBag.CurrentUser = currentUser;116 ViewBag.Messages = messages;117 return View();118}119```120121**View (`Index.cshtml`):**122```razor123@using Syncfusion.EJ2.InteractiveChat124125<div style="height:400px; width:450px;">126 @Html.EJS().ChatUI("chatUI")127 .User(ViewBag.CurrentUser)128 .Messages(ViewBag.Messages)129 .HeaderText("Team Chat")130 .Render()131</div>132```133134**Required layout references (`_Layout.cshtml`):**135```html136<head>137 <link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/{{ site.ej2version }}/fluent.css" />138 <script src="https://cdn.syncfusion.com/ej2/{{ site.ej2version }}/dist/ej2.min.js"></script>139</head>140<body>141 ...142 @Html.EJS().ScriptManager()143</body>144```145146---147148## Common Patterns149150### Programmatically Add a Message (Bot Reply)151```javascript152function onMessageSend(args) {153 var chatUI = ej.base.getInstance(document.getElementById('chatUI'), ejs.interactivechat.ChatUI);154 fetch('/api/bot/reply', {155 method: 'POST',156 headers: { 'Content-Type': 'application/json' },157 body: JSON.stringify({ text: args.message.text })158 })159 .then(r => r.json())160 .then(data => chatUI.addMessage({ text: data.reply, author: botUser }));161}162```163164### Enable File Attachments165```razor166@Html.EJS().ChatUI("chatUI")167 .User(ViewBag.CurrentUser)168 .EnableAttachments(true)169 .AttachmentSettings(new ChatUIFileAttachmentSettings {170 SaveUrl = Url.Content("https://services.syncfusion.com/aspnet/production/api/FileUploader/Save"),171 RemoveUrl = Url.Content("https://services.syncfusion.com/aspnet/production/api/FileUploader/Remove")172 })173 .Render()174```175176### Show Typing Indicator (Client-Side)177```javascript178function onCreated() {179 var chatUI = ej.base.getInstance(document.getElementById('chatUI'), ejs.interactivechat.ChatUI);180 chatUI.typingUsers = [{ id: "user2", user: "Michale Suyama" }];181 chatUI.dataBind();182}183```184185---186187## Key Properties Reference188189| Property | Type | Default | Description |190|----------|------|---------|-------------|191| `User` | `ChatUIUser` | — | Current logged-in user |192| `Messages` | `List<ChatUIMessage>` | `[]` | Initial message collection |193| `HeaderText` | `string` | — | Text shown in header |194| `HeaderIconCss` | `string` | — | CSS class for header icon |195| `ShowHeader` | `bool` | `true` | Show or hide the header |196| `ShowFooter` | `bool` | `true` | Show or hide the footer |197| `Placeholder` | `string` | `"Type your message…"` | Textarea placeholder |198| `Width` | `string` | `"100%"` | Component width |199| `Height` | `string` | `"100%"` | Component height |200| `CssClass` | `string` | — | Custom CSS class |201| `AutoScrollToBottom` | `bool` | `false` | Auto-scroll on new message |202| `ShowTimeStamp` | `bool` | `true` | Show message timestamps |203| `TimeStampFormat` | `string` | `"dd/MM/yyyy hh:mm a"` | Global timestamp format |204| `ShowTimeBreak` | `bool` | `false` | Show date separators |205| `EnableCompactMode` | `bool` | `false` | Align all messages left |206| `LoadOnDemand` | `bool` | `false` | Lazy-load messages on scroll |207| `EnablePersistence` | `bool` | `false` | Persist state across page reloads via localStorage |208| `EnableAttachments` | `bool` | `false` | Enable file attachments |209| `MentionUsers` | `List<ChatUIUser>` | — | Users available for `@` mention |210| `TypingUsers` | `List<ChatUIUser>` | — | Users currently typing |211| `EnableRtl` | `bool` | `false` | Right-to-left layout |212| `Locale` | `string` | `"en"` | Localization culture code |