I am using FullCalendar in my asp.net mvc application. It does not load events. I am getting event list by ajax call. Below is my code. What is wrong with it.?

<div class="row">
    <div class="col-lg-12">
        <section class="panel">
            <div class="panel-body">
                <div id="calendar"></div>
<script type="text/javascript">
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            defaultView: 'agendaweek',
            selectable: false,
            selectHelper: false,
            events: { url: '@Url.Action("GetEvents", "Controller")' }

And the `GetEvents/Controller is as below,

public Json GetEvents()
    string query = "query to get events";
    // columns in result table are: id, title, date

            SqlConnection connection = new SqlConnection("connectionString");

            SqlCommand command = new SqlCommand(query, connection);
            SqlDataReader events = command.ExecuteReader();

            DataTable dt = new DataTable();

            string result = JsonConvert.SerializeObject(DatatableToDictionary(dt, "id"), Newtonsoft.Json.Formatting.Indented);


            return Json(result, JsonRequestBehavior.AllowGet);
        catch (Exception ex) { }

public Dictionary<string, Dictionary<string, object>> DatatableToDictionary(DataTable dt, string id)
    var cols = dt.Columns.Cast<DataColumn>().Where(c => c.ColumnName != id);
    return dt.Rows.Cast<DataRow>()
             .ToDictionary(r => r[id].ToString(),
                           r => cols.ToDictionary(c => c.ColumnName, c => r[c.ColumnName]));

This does not get events, actually this does not call GetEvents(). What is wrong with it?

Related posts

Recent Viewed