Example of Date Range in ASP.NET MVC DateRangePicker Control
In this sample, the date ranges from Jan 15, 2017 - Dec 20, 2017 have been set. All the other dates are out of range and restricted to set or select.
@Html.UiDateRangePicker("daterange_start", "daterange_end", new UiDateRangePickerOptions { Id = "daterange", Placeholder = "Choose a Range", Min = (DateTime)ViewData["minDate"], Max = (DateTime)ViewData["maxDate"] })
<style>
#wrapper { max-width: 246px; margin: 30px auto; padding-top: 50px; }
</style>
<div class="control-section">
<div id="wrapper">
@Html.UiDateRangePicker("daterange_start", "daterange_end", new UiDateRangePickerOptions { Id = "daterange", Placeholder = "Choose a Range", Min = (DateTime)ViewData["minDate"], Max = (DateTime)ViewData["maxDate"] })
</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/DateRange.cshtml; it draws what ViewData holds.
public ActionResult DateRange()
{
ViewData["minDate"] = new DateTime(2017, 01, 15);
ViewData["maxDate"] = new DateTime(2017, 12, 20);
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>
DateRangePicker has min and max supports to restrict the user to select a value from the given range. Only the values in this range will be enabled. In this sample, we have specified min range as Jan 15, 2017 and max range as Dec 20, 2017. User will be able to select the values between this range only.