My goal is to develop a dynamic calendar in ASP.NET MVC that pulls event data from a database to populate it. Right now, the calendar is set up to read a json array of objects, but I am facing an issue with converting my ViewModel data into a format that the calendar can interpret. In my current setup, I pass a ViewModel containing a list of a specific datamodel class as a property, and I need to figure out how to loop through this list in the view to make it compatible with the existing calendar structure.
//Existing Accepted Calendar Input
events: [
{
title: "Birthday Party",
start: new Date(2020, 0, 1),
end: new Date(2020, 0, 13),
},
{
title: 'Birthday Party 2',
start: new Date(2019, 11, 9),
end: new Date(2019, 11, 13),
},
{
title: 'Click for Google',
start: new Date(2019, m, 28),
end: new Date(2019, m, 29),
}
],
//ViewModel for Calendar
public class CalendarViewModel
{
public IEnumerable<CalendarDataModel> data { get; set; }
}
CalendarDataModel
:
public class CalendarDataModel
{
public string Description { set; get; }
public int StartYear { set; get; }
public int StartMonth { set; get; }
public int StartDay { set; get; }
public int EndYear { set; get; }
public int EndMonth { set; get; }
public int EndDay { set; get; }
}
My objective is to find a way to convert the data passed through the ViewModel into a json format that aligns with what the JavaScript-based calendar expects.