Example of Mask Support in ASP.NET MVC TimePicker Control
The following sample demonstrates the time masking functionality in the TimePicker. It allows you to enter a valid value for each mask pattern of the time masking.
@Html.UiTimePicker("timepicker", new UiTimePickerOptions { EnableMask = true, Format = "h:mm a", Placeholder = "Select a time" })
<style>
.control_wrapper { display: block; margin: 0 auto; max-width: 300px; padding: 5% 0; }
.tabs-wrap { padding: 0 0 10px; }
</style>
<div class="control-section">
<div class="control_wrapper">
<div class="tabs-wrap">
<div class="wrap">
@Html.UiTimePicker("timepicker", new UiTimePickerOptions { EnableMask = true, Format = "h:mm a", Placeholder = "Select a time" })
</div>
</div>
</div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class TimePickerController : Controller
{
// The page is Views/TimePicker/InputMask.cshtml; it draws what ViewData holds.
public ActionResult InputMask()
{
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>
TimePicker has an enableMask property that allows you to enable the built-in time masking support. The mask pattern is defined based on the provided time format to the component. If the format is not specified, the mask pattern is formed based on the default format of the current culture.