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