Search results

Getting Started

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

Initialize the Schedule component

We are going to render Schedule component in ASP.NET MVC application. Add the below simple code to your index.cshtml page which is available within the Views/Home folder, to initialize the Schedule.

razor
@Html.EJS().Schedule("schedule").Render()

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

Populating appointments

To populate an empty Schedule with appointments, bind the event data to it by assigning the DataSource property under EventSettings property.

  • Create a new Class in controller page to define the data to be passed to the Scheduler as mentioned below,
public class AppointmentData
{
    public int Id { get; set; }
    public string Subject { get; set; }
    public DateTime StartTime { get; set; }
    public DateTime EndTime { get; set; }
}
  • Now create an instance of the class and add the list of Scheduler data to it within the Index method in controller page, which will then be passed to the View page and bound to the Scheduler dataSource.
public class ScheduleData
{
    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;
    }
}
  • Add the Scheduler code in View page as shown below,
@section ControlsSection {
    <div class = "col-lg-9 control-section">
        <div class = "content-wrapper">
            @Html.EJS().Schedule("schedule").Height("550px").EventSettings(new ScheduleEventSettings { DataSource = ViewBag.appointments }).SelectedDate(new DateTime(2018, 2, 15)).Render()
        </div>
    </div>
}
razor
data.cs
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Schedule

@section ControlsSection{
	<div class="col-lg-9 control-section">
		<div class="content-wrapper">
			@Html.EJS().Schedule("schedule").Height("550px").EventSettings(new ScheduleEventSettings { DataSource = ViewBag.appointments }).SelectedDate(new DateTime(2018, 2, 15)).Render()
		</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.

razor
data.cs
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Schedule

@section ControlsSection{
	<div class="col-lg-9 control-section">
		<div class="content-wrapper">
			@Html.EJS().Schedule("schedule").Height("550px").EventSettings(new ScheduleEventSettings { DataSource = ViewBag.appointments }).SelectedDate(new DateTime(2018, 2, 15)).Render()
		</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 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
razor
data.cs
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Schedule

@section ControlsSection{
    <div class="control-section">
        <div class="content-wrapper">
           @Html.EJS().Schedule("schedule").Width("100%").Views(ViewBag.view).Height("550px").CellTemplate("#apptemplate").SelectedDate(new DateTime(2018, 2, 15)).Render()
        </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.

razor
data.cs
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Schedule

@section ControlsSection{
    <div class="control-section">
        <div class="content-wrapper">
            @Html.EJS().Schedule("schedule").Width("100%").Views(view => { view.Option(View.Week).StartHour("07:00").EndHour("15:00").Add(); view.Option(View.WorkWeek).StartHour("10:00").EndHour("18:00").Add();.Height("550px").SelectedDate(new DateTime(2018, 2, 15)).Render()
        </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();
        }
    }
}