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>
</div>
</section>
</div>
</div>
<script type="text/javascript">
$('#calendar').fullCalendar(
{
header:
{
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultView: 'agendaweek',
selectable: false,
selectHelper: false,
events: { url: '@Url.Action("GetEvents", "Controller")' }
});
</script>
And the `GetEvents/Controller is as below,
public Json GetEvents()
{
string query = "query to get events";
// columns in result table are: id, title, date
try
{
SqlConnection connection = new SqlConnection("connectionString");
connection.Open();
SqlCommand command = new SqlCommand(query, connection);
SqlDataReader events = command.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(events);
string result = JsonConvert.SerializeObject(DatatableToDictionary(dt, "id"), Newtonsoft.Json.Formatting.Indented);
connection.Close();
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?