Example of Month Picker in ASP.NET MVC Calendar Control
The following sample demonstrates the Calendar control acting as a month picker. It allows you to select values in terms of months.
Selected Value:
@Html.UiCalendar(new UiCalendarOptions { Id = "calendar", Start = UiCalendarView.Year, Depth = UiCalendarView.Year, OnChange = "valueChange" })
<style>
#date_label { display: block; width: 248px; color: rgba(0, 0, 0, 0.58); margin-left: 5px; }
.control_wrapper { max-width: 300px; margin: 0 auto; }
.ui-theme-dark #date_label { color: white; }
</style>
<div class="control_wrapper">
<div id="container" style="overflow:auto">
@Html.UiCalendar(new UiCalendarOptions { Id = "calendar", Start = UiCalendarView.Year, Depth = UiCalendarView.Year, OnChange = "valueChange" })
<br />
<span id="date_label"> Selected Value: </span>
</div>
</div>
<script>
// Syncfusion: a month is picked, and written as "MMMM y".
function valueChange(value) {
document.getElementById('date_label').textContent = 'Selected Value: ' + value.toLocaleDateString(undefined, { month: 'long', year: 'numeric' });
}
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class CalendarController : Controller
{
// The page is Views/Calendar/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 Calendar has the Start and the Depth properties that provide options to restrict users from navigating to any Calendar view (year, month, or decade).