Example of Month Range Picker in ASP.NET MVC DateRangePicker Control
The following sample demonstrates the DateRangePicker component acting as a month range picker. It allows you to select values within the range of months.
@Html.UiDateRangePicker("daterangepicker_start", "daterangepicker_end", new UiDateRangePickerOptions { Id = "daterangepicker", Format = "MMM yyyy", Placeholder = "Choose a Range", 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.UiDateRangePicker("daterangepicker_start", "daterangepicker_end", new UiDateRangePickerOptions { Id = "daterangepicker", Format = "MMM yyyy", Placeholder = "Choose a Range", 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 DateRangePickerController : Controller
{
// The page is Views/DateRangePicker/MonthRangePicker.cshtml; it draws what ViewData holds.
public ActionResult MonthRangePicker()
{
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 DateRangePicker has the Start and the Depth properties that provide options to restrict users from navigating to any Calendar view (year, month, or decade).