Example of Date Range in ASP.NET MVC DatePicker Control
Date Range sample illustrates the date selection within the specific range in a calendar by using min and max properties. Here, the date selection range was restricted within a range from 5th to 27th days in a month.
@Html.UiDatePicker("datepicker", new UiDatePickerOptions { Value = (DateTime)ViewData["value"], 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.UiDatePicker("datepicker", new UiDatePickerOptions { Value = (DateTime)ViewData["value"], 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 DatePickerController : Controller
{
// The page is Views/DatePicker/DateRange.cshtml; it draws what ViewData holds.
public ActionResult DateRange()
{
ViewData["value"] = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 10);
ViewData["minDate"] = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 05);
ViewData["maxDate"] = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 27);
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>
Date Range sample illustrates the date selection within the specific range in a calendar by using min and max properties. Here, the date selection range was restricted within a range from 5th to 27th days in a month.