title: Loading events on start from database
body: <p>I want to load all the events from the database in the calendar as the page loads but it's not working. Thedata is comming to the page from database but the object is not showing events.</p>
  
  <p>My model is</p>
  
  <pre><code> public class Calendar
      {
          public int id { get; set; }
          public string title { get; set; }
  
          public DateTime starttime { get; set; }
          public DateTime endtime { get; set; }
      }
  </code></pre>
  
  <p>My controller methods are</p>
  
  <pre><code>[HttpPost]
  public JsonResult dataReceiver(string title)
  {
      Calendar calendar = new Calendar();
      calendar.title = title;
      calendar.starttime = DateTime.UtcNow.ToLocalTime();
      calendar.endtime = DateTime.UtcNow.ToLocalTime().AddDays(5);
      db.Calendars.Add(calendar);
      db.SaveChanges();
      return Json(title, JsonRequestBehavior.AllowGet);
  }
  public ActionResult datasender()
  {
      var search = from m in db.Calendars select m;
      //ViewBag.Message = search.ToList();
      return Json(search.ToList(),JsonRequestBehavior.AllowGet);
  }
  </code></pre>
  
  <p>and my view is </p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;title&gt; Calendar&lt;/title&gt;
      &lt;link href="~/Content/calendar/fullcalendar.css" rel="stylesheet" /&gt;
      &lt;link href="~/Content/calendar/fullcalendar.print.css" rel="stylesheet" media='print' /&gt;
      &lt;link href="~/Content/jquery-ui.min.css" rel="stylesheet" /&gt;
      &lt;style&gt;
          body {
              margin: 40px 10px;
              padding: 0;
              font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
              font-size: 14px;
          }
  
          #calendar {
              max-width: 900px;
              margin: 0 auto;
          }
  
          .fc-ltr {
              background: #ddba8f;
          }
  
          .fc-toolbar {
              background: #c64343;
          }
      &lt;/style&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  
      &lt;div id='calendar' style="height:90%; width:90%; color:black; border:1px solid blue; margin-top:5%; position:relative"&gt;
  
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  
  @section scripts
  {
  &lt;script src="~/Scripts/calendar/moment.min.js"&gt;&lt;/script&gt;
  &lt;script src="~/Scripts/calendar/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="~/Scripts/calendar/fullcalendar.js"&gt;&lt;/script&gt;
  &lt;script src="~/Scripts/calendar/jquery-ui.custom.min.js"&gt;&lt;/script&gt;
      &lt;script&gt;
  
          $(document).ready(function () {
  
              calendarcreate();
              var obj;
          });
  
          function calendarcreate() {
                $.ajax({
                  type: "Post",
                  url: "/Calendar/datasender",
                  dataType: "html",
                  data: {},
                  success: function (data) {
                      obj = JSON.parse(data);
                      alert("successfull data received " + JSON.stringify(obj));
                      var cal = $('#calendar').fullCalendar({
                          header: {
                              left: 'prev,next today',
                              center: 'title',
                              right: 'month,agendaWeek,agendaDay'
                          },
                          defaultDate: '2015-02-12',
                          selectable: true,
                          selectHelper: true,
                          select: function (start, end) {
                              var title = prompt('Event Title:');
                              var eventData;
                              if (title) {
                                  eventData = {
                                      title: title,
                                      start: start,
                                      end: end
                                  };
                                  $('#calendar').fullCalendar('renderEvent', eventData, true); // stick? = true
                              }
                              $('#calendar').fullCalendar('unselect');
                              $.ajax({
                                  type: "Post",
                                  url: "/Calendar/dataReceiver",
                                  dataType: "json",
                                  data: { "title": eventData.title },
                                  success: function (data) {
                                      alert("successfull data send " + data);
                                                            },
                                  error: function (req, status, error) {
                                      alert(error + req + status);
                                                                         }
                                      });
                          },
                          eventClick: function (calEvent, jsEvent, view) {
                              alert(calEvent.title + calEvent.start + calEvent.end +obj)
                                                                           },
                          dragOpacity: .50,
                          dragRevertDuration: 1000,
                          eventColor: '#378006',
                          eventBackgroundColor: 'gray',
                          editable: true,
                          eventStartEditable: true,
                          eventDurationEditable: true,
                          dragScroll: true,
                          eventOverlap: false,
                          eventLimit: true, // allow "more" link when too many events
                          events:
                              [
                              {
                                  title: 'All Day Event',
                                  start: '2015-02-01'
                              },
  
                              {
                                  id: 999,
                                  title: 'Repeating Event',
                                  start: '2015-02-09T16:00:00'
                              },
  
                              {
                                  title: 'Click for Google',
                                  url: 'http://google.com/',
                                  start: '2015-02-28'
                              }
                          ]
                      });
  
                  },
                  error: function (req, status, error) {
                      alert(error + req + status);
                      var div = $('#SearchItemDiv');
                      div.html("");
                      div.append('Error');
                  }
              });
  
  
              }
  
  
      &lt;/script&gt;
  </code></pre>