Example of Track labels, sizes and states in ASP.NET MVC Switch Control
ON/OFF text, small/large switches, label before and disabled state.
Local demo only: use synthetic text, dummy codes/files and scribbles. Do not enter real passwords, personal details or signatures. No new submission endpoint is provided. Event logs contain actions/state only, never field contents.
<div class="input-stack">
<div>@Html.UiSwitch("wifi", true, new UiSwitchOptions { Label = "Demo Wi-Fi", OnChange = "InputEvents.changed" })</div>
<div>@Html.UiSwitch("texts", false, new UiSwitchOptions { Label = "Track labels", OnLabel = "ON", OffLabel = "OFF" })</div>
<div>@Html.UiSwitch("small", true, new UiSwitchOptions { Label = "Small, label before", LabelPosition = UiLabelPosition.Before, Size = UiInputSize.Small })</div>
<div>@Html.UiSwitch("large", false, new UiSwitchOptions { Label = "Large", Size = UiInputSize.Large })</div>
<div>@Html.UiSwitch("disabled", true, new UiSwitchOptions { Label = "Disabled", Enabled = false })</div>
</div>
@section scripts {
<script>
(function (window) {
'use strict';
// Never serialize callback arguments: they may contain typed text, OTPs, file names or image data.
window.InputEvents = {
changed: function () { window.InputSampleLog('Component change/input event'); },
// A demo form: it reports the number of fields and files it holds, never their content, and does not submit.
submitted: function (form) {
var files = 0;
Array.prototype.forEach.call(form.querySelectorAll('input[type=file]'), function (input) { files += input.files ? input.files.length : 0; });
window.InputSampleLog('Form submitted with ' + form.elements.length + ' fields and ' + files + ' files (nothing is sent)');
return false;
}
};
})(window);
</script>
}
<div class="input-sample">
<style>
.input-sample .input-row { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; margin-bottom: 24px; }
.input-sample .input-row > .ui-input-control { flex: 1 1 220px; }
.input-sample .input-stack { display: grid; gap: 18px; max-width: 660px; }
.input-sample .input-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 24px; }
.input-sample .input-actions button { padding: 6px 12px; border: 1px solid var(--ui-border); border-radius: 4px; }
.input-sample .ui-slider { margin: 36px 16px; }
.input-sample .input-log { max-height: 180px; overflow: auto; font: 12px monospace; padding: 12px 28px; border: 1px solid var(--ui-border); }
.input-sample .input-drop { padding: 24px; border: 2px dashed var(--ui-border); }
</style>
<p class="small">Local demo only: use synthetic text, dummy codes/files and scribbles. Do not enter real passwords, personal details or signatures. No new submission endpoint is provided. Event logs contain actions/state only, never field contents.</p>
<div class="input-stack">
<div>@Html.UiSwitch("wifi", true, new UiSwitchOptions { Label = "Demo Wi-Fi", OnChange = "InputEvents.changed" })</div>
<div>@Html.UiSwitch("texts", false, new UiSwitchOptions { Label = "Track labels", OnLabel = "ON", OffLabel = "OFF" })</div>
<div>@Html.UiSwitch("small", true, new UiSwitchOptions { Label = "Small, label before", LabelPosition = UiLabelPosition.Before, Size = UiInputSize.Small })</div>
<div>@Html.UiSwitch("large", false, new UiSwitchOptions { Label = "Large", Size = UiInputSize.Large })</div>
<div>@Html.UiSwitch("disabled", true, new UiSwitchOptions { Label = "Disabled", Enabled = false })</div>
</div>
</div>
@section below {
<div class="input-sample">
<h3 class="h6 mt-3">Event log (actions only)</h3>
<ul id="inputEventLog" class="input-log" aria-live="polite"></ul>
<script>
(function (window, document) {
'use strict';
window.InputSampleLog = function (message) {
var list = document.getElementById('inputEventLog');
if (!list) { return; }
var item = document.createElement('li');
item.textContent = message;
list.insertBefore(item, list.firstChild);
while (list.children.length > 30) { list.removeChild(list.lastChild); }
};
})(window, document);
</script>
</div>
}
@section scripts {
<script>
(function (window) {
'use strict';
// Never serialize callback arguments: they may contain typed text, OTPs, file names or image data.
window.InputEvents = {
changed: function () { window.InputSampleLog('Component change/input event'); },
// A demo form: it reports the number of fields and files it holds, never their content, and does not submit.
submitted: function (form) {
var files = 0;
Array.prototype.forEach.call(form.querySelectorAll('input[type=file]'), function (input) { files += input.files ? input.files.length : 0; });
window.InputSampleLog('Form submitted with ' + form.elements.length + ' fields and ' + files + ' files (nothing is sent)');
return false;
}
};
})(window);
</script>
}
// This sample uses local data: no controller action is needed.
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
@* Controls with a DataUrl: @Html.AntiForgeryToken() on the page and [HttpPost, ValidateJsonAntiForgeryToken] on the action. *@