Search results

Set Default Value for Event Fields in ASP.NET MVC Schedule control

14 Apr 2021 / 1 minute to read

Event window default fields name like Title, Location, etc.. can be customized and default value can be set to Subject field using Default property which will be added if an appointment is created with empty subject.

razor
data.cs
Copied to clipboard
@using Syncfusion.EJ2.Schedule

@(Html.EJS().Schedule("schedule")
    .Width("100%")
    .Height("550px")
    .EventSettings(e => e.Fields(f => 
            f.Subject(sub => sub.Title("Event Name").Name("Subject").Default("Add Name"))
            .Location(loc => loc.Title("Event Location").Name("Location"))
            .Description(des => des.Title("Summary").Name("Description"))
            .StartTime(st => st.Title("From").Name("StartTime"))
            .EndTime(et => et.Title("To").Name("EndTime"))
        )
        .DataSource(ViewBag.datasource)
    )
    .SelectedDate(new DateTime(2018, 2, 15))
    .Render()
)
Copied to clipboard
public ActionResult Index()
{
    ViewBag.datasource = GetScheduleData();
    return View();
}

public List<AppointmentData> GetScheduleData()
{
    List<AppointmentData> appData = new List<AppointmentData>();
    appData.Add(new AppointmentData
    { Id = 1, 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 = 2, Subject = "Milky Way as Melting pot", StartTime = new DateTime(2018, 2, 15, 9, 30, 0), EndTime = new DateTime(2018, 2, 15, 11, 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; }
}