Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are no controllers and actions in WebMatrix WebPages. You need to write a separate <code>.cshtml</code> page that will query the database and serve the JSON to the response:</p> <pre><code>@{ var db = Database.Open("events"); var result = db.Query("SELECT * FROM events"); var data = result.Select(x =&gt; new { id = x.id, title = x.title, start = x.start.ToString("s"), end = x.end.ToString("s"), allDay = false }).ToArray(); Json.Write(data, Response.Output); Response.ContentType = "application/json"; } </code></pre> <p>and then in another page in which you want to display the calendar you could configure it:</p> <pre><code>$(document).ready(function() { $('#calendar').fullCalendar({ theme: true, header: { left: '', center: '', right: '' }, defaultView: 'agendaDay', editable: false, events: '/events.cshtml' }); }); </code></pre> <hr> <p>UPDATE: Here's an example of how you could use parametrized queries:</p> <pre><code>@{ var origin = new DateTime(1970, 1, 1, 0, 0, 0, 0); var fromDate = origin.AddSeconds(int.Parse(Request["start"])); var toDate = origin.AddSeconds(int.Parse(Request["end"])); var db = Database.Open("events"); var sql = "SELECT * FROM events WHERE start &gt;= @0 AND end &lt;= @1"; var result = db.Query(sql, fromDate, toDate); var data = result.Select(x =&gt; new { id = x.id, title = x.title, start = x.start.ToString("s"), end = x.end.ToString("s"), allDay = false }).ToArray(); Json.Write(data, Response.Output); Response.ContentType = "application/json"; } </code></pre> <p>Now you could query the page like this: <code>/events.cshtml?start=5&amp;end=10</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload