Example of Multi Selection in ASP.NET MVC Calendar Control
The following sample demonstrates the multiple date selection functionalities of the Calendar. Click/Touch the desired date from the Calendar and the selected date will be added to the values property of the calendar.
@Html.UiCalendar(new UiCalendarOptions { Id = "calendar", MultiSelect = true, Values = (DateTime[])ViewData["multiValue"], OnChange = "changeValue" })
<style>
#multiselect { display: block; min-height: 40px; margin: 12px 5px; }
.control_wrapper { max-width: 300px; margin: 0 auto; }
</style>
<div class="control_wrapper">
@Html.UiCalendar(new UiCalendarOptions { Id = "calendar", MultiSelect = true, Values = (DateTime[])ViewData["multiValue"], OnChange = "changeValue" })
<br />
<span id="multiselect"></span>
</div>
<script>
// Syncfusion: the selected dates are listed below the calendar.
function changeValue(values) {
var element = document.getElementById('multiselect');
element.innerHTML = '';
(values || []).forEach(function (date) {
element.insertBefore(document.createElement('br'), element.firstChild);
element.insertBefore(document.createTextNode(date.toLocaleDateString()), element.firstChild);
});
}
// The page shows the dates it starts with, as Syncfusion's created event does.
window.addEventListener('load', function () { changeValue(window.Lumen.get('calendar').getValue()); });
</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/MultiSelection.cshtml; it draws what ViewData holds.
public ActionResult MultiSelection()
{
var month = DateTime.Now.Month;
var year = DateTime.Now.Year;
ViewData["multiValue"] = new DateTime[] { new DateTime(year, month, 10), new DateTime(year, month, 15), new DateTime(year, month, 25) };
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>
Multi selection sample demonstrates, how to enable and select the multiple date in a calendar by using isMultiSelection and values properties. Here 10, 15 and 25 dates are selected.