views:

48

answers:

1

Hi, I am implementing the full calender in jquery in my asp.net mvc application by referring from here

but as per this blog it should be render the events on dates given in the controller action. but it is does not. i followed exact same steps . i checked many times there is no mistake. so why should be this happening? please guide me

Edited

Controller:

 public ActionResult CalendarData()
        {
            IList<CalendarDTO> tasksList = new List<CalendarDTO>();

            tasksList.Add(new CalendarDTO
            {
                id = 1,
                title = "Google search",
                start = ToUnixTimespan(DateTime.Now),
                end = ToUnixTimespan(DateTime.Now.AddHours(4)),
                url = "www.google.com"
            });
            tasksList.Add(new CalendarDTO
            {
                id = 1,
                title = "Bing search",
                start = ToUnixTimespan(DateTime.Now.AddDays(1)),
                end = ToUnixTimespan(DateTime.Now.AddDays(1).AddHours(4)),
                url = "www.bing.com"
            });

            return Json(tasksList);
        }

        private long ToUnixTimespan(DateTime date)
        {
            TimeSpan tspan = date.ToUniversalTime().Subtract(
     new DateTime(1970, 1, 1, 0, 0, 0));

            return (long)Math.Truncate(tspan.TotalSeconds);
        }

Added Class

public class CalendarDTO
    {
        public int id { get; set; }
        public string title { get; set; }
        public long start { get; set; }
        public long end { get; set; }
        public string url { get; set; }
    }

Site.Master

<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
<link href="../../Content/fullcalendar.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/fullcalendar.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-1.3.2.js" type="text/javascript"></script>

View Page I used Index page which given as default

   $(document).ready(function() {
       $('#calendar').fullCalendar({
           events: "/Home/CalendarData"
       });
   });  

And added div with id "calender".
-----------------------------------------------------------------------------------------
Edited Quetion 2

As you can see above my method returning the Json out put. but I am getting error as:
This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet.


So I just add the parameter as JsonRequestBehavior.AllowGet to Json() .

but it is asking for download the json output file. rather than this it must be redirect to view as usual , right ? why should this is happening?

A: 

Probably a stupid question but did you include jquery-1.3.2.js and fullcalendar.js in your site? Remember that with the default ASP.NET MVC 2.0 project template, only jquery-1.4.1.js is included in the Scripts folder. Also I would recommend you downloading the latest versions of jquery and the fullCalendar plugin.

Also here's another gotcha when returning JSON in the CalendarData action:

return Json(tasksList, JsonRequestBehavior.AllowGet);

Contrary to ASP.NET MVC 1.0, in ASP.NET MVC 2.0 the JsonRequestBehavior.AllowGet is necessary if you want this action to be accessible over GET which is what I think the calendar plugin is doing.

Of course you would have seen this error if you used FireBug to analyze the AJAX request/response data.

Darin Dimitrov