Example of Month Picker in ASP.NET MVC DatePicker Control
The following sample demonstrates the DatePicker control acting as a month picker. It allows you to select values in terms of months.
@Html.UiDatePicker("datepicker", new UiDatePickerOptions { Value = DateTime.Now, Format = "MMMM y", Start = UiCalendarView.Year, Depth = UiCalendarView.Year })
<style>
#wrapper { max-width: 246px; margin: 30px auto; padding-top: 50px; }
</style>
<div class="control-section">
<div id="wrapper">
@Html.UiDatePicker("datepicker", new UiDatePickerOptions { Value = DateTime.Now, Format = "MMMM y", Start = UiCalendarView.Year, Depth = UiCalendarView.Year })
</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/MonthPicker.cshtml; it draws what ViewData holds.
public ActionResult MonthPicker()
{
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>
The DatePicker has the Start and the Depth properties that provide options to restrict users from navigating to any Calendar view (year, month, or decade).