Set Different Event Time Duration in ASP.NET MVC Scheduler
By default, the start and end time of a new appointment created from a cell click in the Scheduler is calculated by adding the timeScale.interval value (in minutes) to the clicked cell’s start time. The default timeScale.interval is 30, so a new appointment created by clicking a cell lasts 30 minutes.
To override this default appointment length, handle the popupOpen event and assign a new value (in minutes) to args.duration. The change applies only to the Add scenario — when the user clicks an empty cell to create a new appointment. Editing an existing appointment is not affected, since the existing event already has its own start and end times.
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Schedule
<div class="control-section">
<div class="content-wrapper">
@Html.EJS().Schedule("schedule").Width("100%").Height("550px").PopupOpen("onPopupOpen").EventSettings(e => e.DataSource(ViewBag.datasource)).Views(ViewBag.view).SelectedDate(new DateTime(2018, 2, 15)).Render()
</div>
</div>
<script type="text/javascript">
function onPopupOpen(args) {
args.duration = 40;
}
</script>using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplication1.Models;
namespace WebApplication1.Controllers
{
public partial class ScheduleController : Controller
{
public ActionResult event-duration()
{
ViewBag.datasource = new ScheduleData().GetScheduleData();
List<ScheduleViewsModel> viewOption = new List<ScheduleViewsModel>()
{
new ScheduleViewsModel {Option = Syncfusion.EJ2.Schedule.View.Day },
new ScheduleViewsModel {Option = Syncfusion.EJ2.Schedule.View.Week },
new ScheduleViewsModel {Option = Syncfusion.EJ2.Schedule.View.WorkWeek },
new ScheduleViewsModel {Option = Syncfusion.EJ2.Schedule.View.Month }
};
ViewBag.view = viewOption;
return View();
}
}
}NOTE
The value assigned to
args.durationis interpreted as minutes. In the example above,args.duration = 40makes every new appointment 40 minutes long.