Loading...
Loading...
Guide for implementing Syncfusion ASP.NET Core Switch component. Use this skill when creating a toggle button/switch for form inputs or state management. Covers installation, basic implementation, property configuration, event handling, and styling customization. Provides guidance on getting started, properties, events, and styling documentation.
npx skill4agent add syncfusion/aspnetcore-ui-components-skills syncfusion-aspnetcore-switch<!-- In ~/Pages/Shared/_ViewImports.cshtml (if not already added) -->
@addTagHelper *, Syncfusion.EJ2
<!-- In ~/Pages/Index.cshtml -->
<div class="switch-container">
<label>Enable Notifications</label>
<ejs-switch id="switchId"></ejs-switch>
</div><ejs-switch id="switchWithLabels"
onLabel="ON"
offLabel="OFF">
</ejs-switch><ejs-switch id="switchWithEvent"
change="onChange">
</ejs-switch>
<script>
function onChange(args) {
console.log('Switch state changed:', args.checked);
// Update UI or call server
}
</script><!-- Page Model: public bool NotificationEnabled { get; set; } -->
<ejs-switch id="notificationSwitch"
checked="@Model.NotificationEnabled"
change="onNotificationChange">
</ejs-switch>
<script>
function onNotificationChange(args) {
// Update form data for submission
document.getElementById('notificationValue').value = args.checked;
}
</script><!-- Disable Switch based on condition -->
<ejs-switch id="premiumSwitch"
disabled="@(!Model.IsPremiumUser)">
</ejs-switch><div class="preferences">
<div class="preference-item">
<label>Email Notifications</label>
<ejs-switch id="emailSwitch"></ejs-switch>
</div>
<div class="preference-item">
<label>SMS Notifications</label>
<ejs-switch id="smsSwitch"></ejs-switch>
</div>
</div>| Property | Type | Description | When to Use |
|---|---|---|---|
| boolean | Initial state (true = on, false = off) | Set default switch position on page load |
| boolean | Disable interaction (true/false) | Show but prevent changes (permissions, loading) |
| string | HTML form name attribute | Form submission and server-side binding |
| string | HTML form value | Custom value sent to server |
| string | Text shown in "on" state | Clarify the enabled option |
| string | Text shown in "off" state | Clarify the disabled option |
| function | Event handler for state changes | React to user interaction |
| string | Custom CSS class for styling | Apply theme or custom appearance |