Example of Mask Support in ASP.NET MVC DateTimePicker Control
The following sample demonstrates the date time masking functionality in the DateTimePicker. It allows you to enter a valid value for each mask pattern of the date time masking.
@Html.UiDateTimePicker("datetime", new UiDateTimePickerOptions { EnableMask = true, Format = "M/d/yyyy hh:mm a" })
<style>
#wrapper { max-width: 246px; margin: 30px auto; padding-top: 50px; }
</style>
<div class="control-section">
<div id="wrapper">
@Html.UiDateTimePicker("datetime", new UiDateTimePickerOptions { EnableMask = true, Format = "M/d/yyyy hh:mm a" })
</div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class DateTimePickerController : Controller
{
// The page is Views/DateTimePicker/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>
DateTimePicker has an enableMask property that allows you to enable the built-in date time masking support. The mask pattern is defined based on the provided date 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.