Reputation: 992
I am working with the jQuery fullcalendar plugin and mvc3.
jQuery:
$(document).ready(function () {
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev, next, today',
center: 'title',
right: 'month, agendaWeek, agendaDay'
},
events: 'CalendarView/GetEvents/'
});
});
Controller (It doesn't get into this function):
public JsonResult GetEvents(double start, double end)
{
var DateStart = ConvertFromUnixTimestamp(start);
var DateEnd = ConvertFromUnixTimestamp(end);
var JsonRfc = Repo.getCalendar(DateStart, DateEnd);
var ret = JsonRfc.ToArray();
return Json(ret, JsonRequestBehavior.AllowGet);
}
The code inside the controller never gets executed. Does anyone have any insight as to why?
Thanks.
Upvotes: 0
Views: 880
Reputation: 31
I had the same problem as you. Using Firebug I realized that the call is actually in the following form: GetEvents?start=2014-06-29&end=2014-08-10&_=1404512824620 which means that start and end aren't doubles. Changing GetEvents so that start and end are strings finally worked. You can then convert the string to the appropriate format.
Upvotes: 0
Reputation: 14219
As Phil.Wheeler suggested, use a browser debugger to find out what's going on, though I can say this:
If you're getting a 500 server error it's likely the function requirements are not being met in order to execute (assuming you're actually hitting the right URL for the controller).
Further to that, your method should be decorated with [HttpPost]
[HttpPost]
public JsonResult GetEvents(double start, double end)
Upvotes: 0
Reputation: 1467
Using Fiddler, I found out that my problem was that my method didn't have the correct variable names of 'start' and 'end'. That was the reason for my server error 500.
Upvotes: 0
Reputation: 82
$.ajax always works for me:
$.ajax({
type:"GET",
url: "/CalendarView/Events",
data: {start:"", end:""},
datatype: "json"
success: function (result) {
var calendar = $("#Calendar").fullCalendar({
//define calendar for result.objectreturned
});
},
error: function () {
alert("error");
},
});
Also your controller can be changed to:
var ret = JsonRfc.ToList();
This should work 100%.
Upvotes: 0
Reputation: 3181
Ensure that the path to your controller/action is correct. Depending on how your app is installed it may or may not be right. As long as your javascript code is inside one of your views you might try with
events: '@Url.Action("GetEvents","CalendarView")'
You definetly should, as @Phil.Wheeler suggested, take a closer look at what will pop up in Firebug / IE Developer Tools / Chrome Developer tools. (or try http://www.fiddler2.com/fiddler2/ if you want something outside of your browser )
The other way you might want to try is retrieving JSON object first with
$.getJSON('CalendarView/GetEvents/', function(data) {
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev, next, today',
center: 'title',
right: 'month, agendaWeek, agendaDay'
},
events: data
});
}
Upvotes: 2
Reputation: 16858
Your JsonResult expects two parameters for Start and End which don't appear to be getting passed by your Ajax method.
Have you considered installing Glimpse or checking what codes come back in Firebug? This might give you some more insight into the behaviour of your actual web traffic.
Upvotes: 1