Example of Lists, direction and individual buttons in ASP.NET MVC RadioButton Control
Vertical and horizontal lists, selected/disabled choices and independently placed radios with one name.
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.
@{
var shipping = new List<SelectListItem>
{
new SelectListItem { Value = "standard", Text = "Standard", Selected = true },
new SelectListItem { Value = "express", Text = "Express" },
new SelectListItem { Value = "pickup", Text = "Pickup" },
new SelectListItem { Value = "unavailable", Text = "Unavailable", Disabled = true }
};
}
<div class="input-stack">
@Html.UiRadioButtonList("shipping", shipping, new UiRadioButtonListOptions { Id = "shippingGroup", Label = "Horizontal", Direction = UiRadioDirection.Horizontal, OnChange = "InputEvents.changed" })
@Html.UiRadioButtonList("vertical", shipping, new UiRadioButtonListOptions { Label = "Vertical, label before", LabelPosition = UiLabelPosition.Before, Size = UiInputSize.Small })
<div>@Html.UiRadioButton("placed", "a", true, new UiRadioButtonOptions { Label = "Independent A", Size = UiInputSize.Large, OnChange = "InputEvents.changed" })</div>
<div>@Html.UiRadioButton("placed", "b", false, new UiRadioButtonOptions { Label = "Independent B" })</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>
@{
var shipping = new List<SelectListItem>
{
new SelectListItem { Value = "standard", Text = "Standard", Selected = true },
new SelectListItem { Value = "express", Text = "Express" },
new SelectListItem { Value = "pickup", Text = "Pickup" },
new SelectListItem { Value = "unavailable", Text = "Unavailable", Disabled = true }
};
}
<div class="input-stack">
@Html.UiRadioButtonList("shipping", shipping, new UiRadioButtonListOptions { Id = "shippingGroup", Label = "Horizontal", Direction = UiRadioDirection.Horizontal, OnChange = "InputEvents.changed" })
@Html.UiRadioButtonList("vertical", shipping, new UiRadioButtonListOptions { Label = "Vertical, label before", LabelPosition = UiLabelPosition.Before, Size = UiInputSize.Small })
<div>@Html.UiRadioButton("placed", "a", true, new UiRadioButtonOptions { Label = "Independent A", Size = UiInputSize.Large, OnChange = "InputEvents.changed" })</div>
<div>@Html.UiRadioButton("placed", "b", false, new UiRadioButtonOptions { Label = "Independent B" })</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. *@