Example of Default Functionalities in ASP.NET MVC OtpInput Control
This sample demonstrates the default functionalities of the OTP Input control. It allows users to enter OTP (One-Time Password) during MFA processes such as login, account verifications, booking activities, and more.
@Html.UiOtpInput("numberOtp", new UiOtpInputOptions { Value = "1234", Type = UiOtpInputType.Number, AriaLabel = "Number OTP" })
@Html.UiOtpInput("textOtp", new UiOtpInputOptions { Value = "e3c7", Type = UiOtpInputType.Text, AriaLabel = "Text OTP" })
@Html.UiOtpInput("passwordOtp", new UiOtpInputOptions { Type = UiOtpInputType.Password, AriaLabel = "Password OTP" })
<style>
.property-section .property-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.property-section .prop-input { width: 90px; padding: 4px 6px; border: 1px solid var(--ui-input-border); border-radius: var(--ui-radius); background: var(--ui-surface); color: var(--ui-text); font: inherit; }
.otp-container { width: 240px; margin: 50px auto; }
.otp-container label { display: block; margin-bottom: 15px; }
</style>
<div class="control-section">
<div class="otp-container">
<label for="numberOtp">Default (Number) OTP Input</label>
@Html.UiOtpInput("numberOtp", new UiOtpInputOptions { Value = "1234", Type = UiOtpInputType.Number, AriaLabel = "Number OTP" })
</div>
<div class="otp-container">
<label for="textOtp">Text OTP Input</label>
@Html.UiOtpInput("textOtp", new UiOtpInputOptions { Value = "e3c7", Type = UiOtpInputType.Text, AriaLabel = "Text OTP" })
</div>
<div class="otp-container">
<label for="passwordOtp">Password OTP Input</label>
@Html.UiOtpInput("passwordOtp", new UiOtpInputOptions { Type = UiOtpInputType.Password, AriaLabel = "Password OTP" })
</div>
</div>
<script>
// Syncfusion starts the password input with 1234; a password is never written into the page, so the script puts the demo value in
window.addEventListener('load', function () { window.Lumen.get('passwordOtp').setValue('1234'); });
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class OtpInputController : Controller
{
// The page is Views/OtpInput/DefaultFunctionalities.cshtml; it draws what ViewData holds.
public ActionResult DefaultFunctionalities()
{
return View();
}
}
}
@* 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>
This example showcases the usage of the Type and Value properties in the OTP Input control. The available input types are Number, Text and Password. Once the user enters the OTP according to the specified Type, the Value property can be used to access the entered OTP.