Search results

Getting Started

This section briefly explains about how to include a simple Schedule in your ASP.NET Core application. You can refer the ASP.NET Core Getting Started documentation page for introduction part of the system requirements and common component configurations.

Initialize the Schedule component

Schedule component can be rendered by using the ejs-schedule tag helper in ASP.NET Core application. Add the below simple code to your index.cshtml page which is available within the Views/Home folder, to initialize the Schedule.

tagHelper
<ejs-schedule id="schedule"></ejs-schedule>

Running the above code will display the empty Schedule on the browser.

Populating appointments

  • To populate the empty Schedule with appointments, bind the event data to it by assigning the dataSource property under e-schedule-eventsettings directive.
tagHelper
data.cs
@using Syncfusion.EJ2

@section ControlsSection{
    <div class="control-section">
        <div class="control_wrapper schedule-control-section">
            <ejs-schedule id="schedule" height="550" selectedDate="new DateTime(2018, 2, 15)">
                <e-schedule-eventsettings dataSource="@ViewBag.appointments"></e-schedule-eventsettings>
            </ejs-schedule>
        </div>
    </div>
}
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 IActionResult WorkDays()
        {
            ViewBag.appointments = GetScheduleData();
            return View();
        }
        public List<AppointmentData> GetScheduleData()
        {
            List<AppointmentData> appData = new List<AppointmentData>();
            appData.Add(new AppointmentData
            {Id = 1, Subject = "Explosion of Betelgeuse Star", StartTime = new DateTime(2018, 2, 11, 9, 30, 0), EndTime = new DateTime(2018, 2, 11, 11, 0, 0) });
            appData.Add(new AppointmentData
            { Id = 2, Subject = "Thule Air Crash Report", StartTime = new DateTime(2018, 2, 12, 12, 0, 0), EndTime = new DateTime(2018, 2, 12, 14, 0, 0) });
            appData.Add(new AppointmentData
            { Id = 3, Subject = "Blue Moon Eclipse", StartTime = new DateTime(2018, 2, 13, 9, 30, 0), EndTime = new DateTime(2018, 2, 13, 11, 0, 0) });
            appData.Add(new AppointmentData
            { Id = 4, Subject = "Meteor Showers in 2018", StartTime = new DateTime(2018, 2, 14, 13, 0, 0), EndTime = new DateTime(2018, 2, 14, 14, 30, 0) });
            appData.Add(new AppointmentData
            { Id = 5, Subject = "Milky Way as Melting pot", StartTime = new DateTime(2018, 2, 15, 12, 0, 0), EndTime = new DateTime(2018, 2, 15, 14, 0, 0) });
            return appData;
        }
    }
	
    public class AppointmentData
    {
        public int Id { get; set; }
        public string Subject { get; set; }
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }
    }
}

Setting date

Scheduler usually displays the system date as its current date. To change the current date of scheduler with specific date, define the selectedDate property.

tagHelper
data.cs
@using Syncfusion.EJ2

@section ControlsSection{
    <div class="control-section">
        <div class="control_wrapper schedule-control-section">
            <ejs-schedule id="schedule" height="550" selectedDate="new DateTime(2018, 2, 15)">
                <e-schedule-eventsettings dataSource="@ViewBag.appointments"></e-schedule-eventsettings>
            </ejs-schedule>
        </div>
    </div>
}
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 IActionResult WorkDays()
        {
            ViewBag.appointments = GetScheduleData();
            return View();
        }
        public List<AppointmentData> GetScheduleData()
        {
            List<AppointmentData> appData = new List<AppointmentData>();
            appData.Add(new AppointmentData
            {Id = 1, Subject = "Explosion of Betelgeuse Star", StartTime = new DateTime(2018, 2, 11, 9, 30, 0), EndTime = new DateTime(2018, 2, 11, 11, 0, 0) });
            appData.Add(new AppointmentData
            { Id = 2, Subject = "Thule Air Crash Report", StartTime = new DateTime(2018, 2, 12, 12, 0, 0), EndTime = new DateTime(2018, 2, 12, 14, 0, 0) });
            appData.Add(new AppointmentData
            { Id = 3, Subject = "Blue Moon Eclipse", StartTime = new DateTime(2018, 2, 13, 9, 30, 0), EndTime = new DateTime(2018, 2, 13, 11, 0, 0) });
            appData.Add(new AppointmentData
            { Id = 4, Subject = "Meteor Showers in 2018", StartTime = new DateTime(2018, 2, 14, 13, 0, 0), EndTime = new DateTime(2018, 2, 14, 14, 30, 0) });
            appData.Add(new AppointmentData
            { Id = 5, Subject = "Milky Way as Melting pot", StartTime = new DateTime(2018, 2, 15, 12, 0, 0), EndTime = new DateTime(2018, 2, 15, 14, 0, 0) });
            return appData;
        }
    }
	
    public class AppointmentData
    {
        public int Id { get; set; }
        public string Subject { get; set; }
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }
    }
}

Specific view

Scheduler displays week view by default. To change the current view, define the applicable view name to the currentView property. The applicable view names are,

  • Day
  • Week
  • WorkWeek
  • Month
  • Agenda
  • MonthAgenda
  • TimelineDay
  • TimelineWeek
  • TimelineWorkWeek
  • TimelineMonth
tagHelper
data.cs
@using Syncfusion.EJ2

@section ControlsSection{
    <div class="control-section">
        <div class="control_wrapper schedule-control-section">
            <ejs-schedule id="schedule" height="550" view="@ViewBag.view" cellTemplate="#apptemplate" selectedDate="new DateTime(2018, 2, 15)">
            </ejs-schedule>
        </div>
    </div>
    <script id="apptemplate" type="text/template">
        ${if (type === "monthCells")}
        <div class="templatewrap">
            ${getCellContent(data.date)}
        </div> ${/if}
    </script>
    <script type="text/javascript">
        function getCellContent(date) {
            var weekEnds = [0, 6];
            if (weekEnds.indexOf(date.getDay()) >= 0) {
                return "<img src='weekend.png' /><span class='caption'>Weekend</span>";
            }
            return '';
        }
    </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 specific-views()
        {
            List<ScheduleViewsModel> viewOption = new List<ScheduleViewsModel>()
            {
                new ScheduleViewsModel {Option = Syncfusion.EJ2.Schedule.View.Week, ShowWeekend = false },
                new ScheduleViewsModel {Option = Syncfusion.EJ2.Schedule.View.Month}
            };
            ViewBag.view = viewOption;
            return View();
        }
    }
}

Individual view customization

Each individual scheduler views can be customized with its own options such as setting different start and end hour on Week and Work Week views, whereas hiding the weekend days on Month view alone. This can be achieved by defining views property to accept the array of object type, where each object depicts the individual view customization.

tagHelper
data.cs
@using Syncfusion.EJ2

@section ControlsSection{
    <div class="control-section">
        <div class="control_wrapper schedule-control-section">
            <ejs-schedule id="schedule" height="550" view="@ViewBag.view" selectedDate="new DateTime(2018, 2, 15)">
            <e-schedule-views>
                <e-view option="WorkWeek" startHour="07:00" endHour="15:00"></e-view>
                <e-view option="Week" startHour="10:00" endHour="18:00"></e-view>
                </e-schedule-views>
            </ejs-schedule>
        </div>
    </div>
}
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 views()
        {
            ViewBag.datasource = new ScheduleData().GetScheduleData();
            return View();
        }
    }
}