Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7536579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:36:47+00:00 2026-05-30T06:36:47+00:00

I have an SQL server with the following layout Table ( id int title

  • 0

I have an SQL server with the following layout

Table (    id int
           title varchar(40),
           start Date(),
           end Date(),
           allDay bool,
           username varchar(40)
      );

I have gotten the following code from this blog to create a JSON object from the data I wish to use, however his data is stored differently. How do I create the same object, extracted from my database?

I am guessing I need to make the file a .cshtml file rather than a .js file and use this :

@{
    var db = Database.Open("events"); 
    var selectQueryString = "SELECT * FROM events";
}

 @foreach(var row in db.Query(selectQueryString)){ }

But how do I adapt this code to produce the same JSON object?

Here is the relevant code from the blog, my attempt is below :

public JsonResult GetEvents(double start, double end)
{
    var userName = Session["UserName"] as string;
    if(string.IsNullOrEmpty(userName))
    {
        return null;
    }

    var fromDate = ConvertFromUnixTimestamp(start);
    var toDate = ConvertFromUnixTimestamp(end);

    var rep = Resolver.Resolve<IEventRepository>();
    var events = rep.ListEventsForUser(userName,fromDate,toDate);

    var eventList = from e in events
                    select new {
                                id = e.Id,
                                title = e.Title,
                                start = e.FromDate.ToString("s"),
                                end = e.ToDate.ToString("s"),
                                allDay = false
                            }; 

    var rows = eventList.ToArray();
    return Json(rows,JsonRequestBehavior.AllowGet);           
}

Edit :

I am now working with the following .cshtml code for the GetEvents command, but it will not work. Does anybody have any ideas ?

   @{ 
        var origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
        var fromDate = origin.AddSeconds((Request["start"]));
        var toDate = origin.AddSeconds(Request["end"]);

        var db = Database.Open("events");
        var result = db.Query("SELECT * FROM events");
        var data = result.Select(x => 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";
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:36:50+00:00Added an answer on May 30, 2026 at 6:36 am

    There are no controllers and actions in WebMatrix WebPages. You need to write a separate .cshtml page that will query the database and serve the JSON to the response:

    @{
        var db = Database.Open("events");
        var result = db.Query("SELECT * FROM events");
        var data = result.Select(x => 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";
    }
    

    and then in another page in which you want to display the calendar you could configure it:

    $(document).ready(function() {             
        $('#calendar').fullCalendar({ 
            theme: true, 
            header: { 
                left: '', 
                center: '', 
                right: '' 
            }, 
            defaultView: 'agendaDay', 
            editable: false, 
            events: '/events.cshtml' 
        }); 
    });
    

    UPDATE: Here’s an example of how you could use parametrized queries:

    @{
    
        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 >= @0 AND end <= @1";
        var result = db.Query(sql, fromDate, toDate);
        var data = result.Select(x => 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";
    }
    

    Now you could query the page like this: /events.cshtml?start=5&end=10

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In MICROSOFT SQL SERVER have the following table: CREATE TABLE [T1] ( [ID] int
I have the following table and data in SQL Server 2005: create table LogEntries
I have the following table variable in SQL Server 2005: DECLARE @results TABLE (id
I have the following table in SQL Server 2000: TABLE_NAME | COLUMN_NAME | TYPE_NAME
I have a following scenario in my SQL Server 2005 database. zipcodes table has
In sql server 2008, I have the following query: select c.title as categorytitle, s.title
I have a Sql Server 2005 table with following data: idHearing is the primary
I have sql server 2008 db table FILE_DETAILS in following format. ID FileName Filesize_in_MB
I have a SQL Server table that contains the following fields: SessionId (guid) Message
I have an SQL Server database table created by deploying the following description in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.