Example of Day Span in ASP.NET MVC DateRangePicker Control
In this sample, your date range selection is restricted to select minimum four days and maximum ten days.
@Html.UiDateRangePicker("daterange_start", "daterange_end", new UiDateRangePickerOptions { Id = "daterange", Placeholder = "Select a Range", MinDays = 4, MaxDays = 10 })
<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 = "Select a Range", MinDays = 4, MaxDays = 10 })
</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/DaySpan.cshtml; it draws what ViewData holds.
public ActionResult DaySpan()
{
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 minDays and maxDays supports to force the user to select the minimum and maximum number of days in the range. Only the values in this range will be enabled.
For example, in some hotel booking website, we need to book rooms that includes packages like minimum 3 days to maximum 4 days. For this scenario this feature can be used.