How to get events from database with FullCalendar v4 using ASP.NET Core?

I’m trying to get the events that I’ve saved in my database to show at the calendar.

As you can see, the database saving part is OK.

Database Table Event Content

But when I try to get all these events from database using the following code,

            $.ajax({
                type: "GET",
                url: "/Escala/GetEvents",
                success: function (data) {
                    $.each(data, function (i, v) {
                        events.push({
                            eventID: v.EventID,
                            title: v.Titulo,
                            start: moment(v.Inicio),
                            end: v.Fim != null ? moment(v.Fim) : null,
                            color: v.Cor,
                            allDay: v.DiaInteiro
                        });
                    })
                    GenerateCalender(events);
                },
                error: function (error) {
                    alert('Failed');
                }
            }) 

… I get some console errors

Errors

This is the /Escala/GetEvents function I’m using to get them:

        public System.Web.Mvc.JsonResult GetEvents()
        {
            var events = _context.Eventos.ToList();
            return new System.Web.Mvc.JsonResult { Data = events, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        } 

Do you have any idea how I can fix it? Thanks in advance!

Archive from: https://stackoverflow.com/questions/59011662/how-to-get-events-from-database-with-fullcalendar-v4-using-asp-net-core

Leave a Reply

Your email address will not be published. Required fields are marked *