locked
MVC 5 FullCalendar v2.4.0 project, events: “/home/getevents/” doesn’t work RRS feed

  • Question

  • User472401502 posted

    Hello everyone, here is a simple problem when i follow this tutorial http://venkatbaggu.com/calendar-in-asp-net-mvc/ using MVC 5 and FullCalendar v2.4.0, events: 'Home/GetEvents' doesn't call the function in my HomeController, anybody know how to resolve this? please help, thanks alot.

    Tuesday, December 22, 2015 7:15 PM

Answers

All replies

  • User61956409 posted

    Hi Supreme7e,

    Firstly, do you get any errors in your browser? Besides, you could try to set event option to this.

    events: '<%= Url.Action("GetEvents", "YourController") %>'
    //or
    //events: "/YourController/GetEvents/"

    Best Regards,

    Fei Han

    Wednesday, December 23, 2015 7:26 AM
  • User472401502 posted

    Thanks for the response. There is no error, the calendar loads when i run the application, but not showing those events.

    Here is the code in my HomeController

    public JsonResult GetEvent(double start, double end)
            {
                var fromDate = ConvertFromUnixTimestamp(start);
                var toDate = ConvertFromUnixTimestamp(end);
    
                var eventList = GetEvents();
    
                var rows = eventList.ToArray();
                return Json(rows, JsonRequestBehavior.AllowGet);
            }
    
            private static DateTime ConvertFromUnixTimestamp(double timestamp)
            {
                var origion = new DateTime(1900, 1, 1, 0, 0, 0, 0);
                return origion.AddSeconds(timestamp);
            }
    
            private List<Events> GetEvents()
            {
                List<Events> eventList = new List<Events>();
    
                Events newEvent = new Events
                {
                    id = "1",
                    title = "Event 1",
                    start = DateTime.Now.AddDays(1).ToString("s"),
                    end = DateTime.Now.AddDays(1).ToString("s"),
                    allDay = false
                };
    
                eventList.Add(newEvent);
    
                newEvent = new Events
                {
                    id = "1",
                    title = "Event 3",
                    start = DateTime.Now.AddDays(2).ToString("s"),
                    end = DateTime.Now.AddDays(3).ToString("s"),
                    allDay = false
                };
    
                eventList.Add(newEvent);
    
                return eventList;
            }

    I have tried many ways in the index view page such as:

    @section scripts{
        <script type="text/javascript">
            $(document).ready(function () {
                $('#calendar').fullCalendar({
                    events: '<%= Url.Action("GetEvent", "Home") %>'
                    
                    //or
                    //events: "/Home/GetEvent/"
                });
            });
        </script>
    }

    when i try to debug it,

    @section scripts{
        <script type="text/javascript">
            $(document).ready(function () {
                $('#calendar').fullCalendar({
                    events: {
                        url: '<%= Url.Action("GetEvent", "Home") %>',
                        type: 'GET',
    success: function()
                        {
                            alert('success');
                        }, error: function() { alert('Error: Can\'t fetch events'); } } }); }); </script> }

    it shows the error alert message. But those events still not showing on the calendar. Any solutions? Thanks alot

    Wednesday, December 23, 2015 5:23 PM
  • User61956409 posted

    Hi Supreme7e,

    You could try to ask for help on FullCalendar support forum.

    http://fullcalendar.io/support/

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 29, 2015 8:58 AM