Populating FullCalendar events from MVC

Posted by jasonmhirst on Stack Overflow See other posts from Stack Overflow or by jasonmhirst
Published on 2010-03-18T10:06:03Z Indexed on 2010/03/18 10:11 UTC
Read the original article Hit count: 917

Filed under:
|
|

I've having difficulty in populating FullCalendar from MVC and would like a little assistance on the matter please.

I have the following code for my controller:

    Function GetEvents(ByVal [start] As Double, ByVal [end] As Double) As JsonResult
    Dim sqlConnection As New SqlClient.SqlConnection

    sqlConnection.ConnectionString = My.Settings.sqlConnection

    Dim sqlCommand As New SqlClient.SqlCommand
    sqlCommand.CommandText = "SELECT tripID AS ID, tripName AS Title, DATEDIFF(s, '1970-01-01 00:00:00', dateStart) AS [Start], DATEDIFF(s, '1970-01-01 00:00:00', dateEnd) AS [End] FROM tblTrip WHERE userID=18 AND DateStart IS NOT NULL"
    sqlCommand.Connection = sqlConnection

    Dim ds As New DataSet
    Dim da As New SqlClient.SqlDataAdapter(sqlCommand)
    da.Fill(ds, "Meetings")
    sqlConnection.Close()

    Dim meetings = From c In ds.Tables("Meetings") Select {c.Item("ID"), c.Item("Title"), "False", c.Item("Start"), c.Item("End")}

    Return Json(meetings.ToArray(), JsonRequestBehavior.AllowGet)

End Function

This does indeed run correctly but the format that is returned is:

[[25,"South America 2008","False",1203033600,1227657600],[48,"Levant 2009","False",1231804800,1233619200],[49,"South America 2009","False",1235433600,1237420800],[50,"Italy 2009","False",1241049600,1256083200],[189,"Levant 2010a","False",1265414400,1267574400],[195,"Levant 2010a","False",1262736000,1262736000],[208,"Levant 2010a","False",1264982400,1267574400],[209,"Levant 2010a","False",1264982400,1265587200],[210,"Levant 2010","False",1264982400,1266969600],[211,"Levant 2010 b","False",1267056000,1267574400],[213,"South America 2010a","False",1268438400,1269648000],[214,"Levant 2010 c","False",1266364800,1264118400],[215,"South America 2010a","False",1268611200,1269648000],[217,"South America 2010","False",1268611200,1269561600],[218,"South America 2010 b","False",1268956800,1269388800],[227,"levant 2010 b","False",1265846400,1266192000]]

And this is totally different to what I've seen on the post from here: http://stackoverflow.com/questions/2445359/jquery-fullcalendar-json-date-issue

(note the lack of tag information and curly braces)

Can someone please explain to me what I may be doing wrong and why my output isn't correctly formatted.

TIA

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about mvc