search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Backend ActionResult 'Events' not running?

Asked by Coop
3 years ago.

Hi all,

Trying to follow the 'HTML5 Event Calendar (Open-Source)' tutorial to load some events from an SQL database table. Set up my project same-as example yet can't get Events to load. Using debug.writeline has helped me to determine that the 'Events' function in BackendController isn't being run.

Backend controller is setup like so:

###########################

public class BackendController : Controller
{
CalendarEntities db = new CalendarEntities();

public class JsonEvent
{
public string id { get; set; }
public string text { get; set; }
public string start { get; set; }
public string end { get; set; }
}

public ActionResult Events(DateTime? start, DateTime? end)
{
Debug.WriteLine("Events called");

// SQL: SELECT * FROM [event] WHERE NOT (([end] <= @start) OR ([start] >= @end))
var events = from ev in db.CalendarShift.AsEnumerable() where !(ev.end <= start || ev.start >= end) select ev;

var result = events
.Select(e => new JsonEvent()
{
start = e.start.ToString("s"),
end = e.end.ToString("s"),
text = e.name,
id = e.id.ToString()
})
.ToList();

return new JsonResult { Data = result };
}

}

###########################

Relevant part of script that should be calling this function is:

###########################

function loadEvents() {
var start = dp.visibleStart();
var end = dp.visibleEnd();

$.post("backend/events",
{
start: start.toString(),
end: end.toString()
},
function (data) {
console.log(data);
dp.events.list = data;
dp.update();
});
}

###########################

loadEvents(); is called right before the above code.

I'm not getting any java/jquery errors and as far as I can tell all scripts are being loaded correctly. I can't find any differences between the demo project and mine, excepting that mine is getting the events from the database table (called 'CalendarShifts').

I'm not getting an "Events called" output in the console when debugging (though when adding the Debug.Writeline into the demo project, I am).

Is anyone able to assist?

Many thanks.

Answer posted by Dan Letecky [DayPilot]
3 years ago.

If you open developer tools in Chrome (Ctrl-Shift-I) and reload the page you will see all AJAX requests in the Network tab.

You should be able to check:

1. If the request has been made
2. What is the request URL (is it the expected location?)
3. The response status code (e.g. 404 for not found)
4. Error message in the response body

My guess would be #2/#3 - the URL in $.post() call is relative ("backend/events"). If you open the page using /Home/Index or from any other location that root ("/") you will not be able to reach the backend.

Try using "/backend/events" or use @Url.Action() instead.

Comment posted by Coop
3 years ago.

G'day, Dan. Thanks for the reply.

I ended up switching to the MVC version of DayPilot, re-wrote the relevant parts and everything is now working perfectly. No idea what the problem was but thanks for the info anyway, I'm sure it'll come in handy later on.

Cheers.

This question is more than 3 months old and has been closed. Please create a new question if you have anything to add.