1

I am developing application in asp.net MVC My Script is :

 $(document).ready
     (
       function() {

        var officerid = document.getElementById('officerid').value;
        url = "/TasksToOfficer/Calender/" + officerid;

     var data=   function() 
                {
               $.ajax(
               {
                         type: 'GET',
                         url: url ,
                         dataType: 'json',
                         data: {'start' : start,'end' : end}
                }); 
                }; 


});

I am unable to get data from my controller action :

    [HttpGet]
        [AcceptVerbs(HttpVerbs.Get)]

 public JsonResult Calender(Guid id)
        { 
        List<TasksToOfficer> officersTasks = null;
        IList<CalendarDTO> tasksList = new List<CalendarDTO>();
        List<TasksToOfficer> officersTasksRecived = null;
            if (String.Compare(Convert.ToString(Session["Role"]), RolesEnum.Admin.ToString())!=0)
            {
                officersTasksRecived = tasks_to_officer_management.GetTasksToOfficers(id);
                foreach (TasksToOfficer tt in officersTasksRecived)
                {
                    DateTime dt = Convert.ToDateTime(tt.Date);
                    tasksList.Add(new CalendarDTO
                    {
                    id=tt.Id,
                    title =tt.Description,
                    start = ToUnixTimespan(dt),
                    end = ToUnixTimespan(dt),
                    url =""}
                    );
                }
            }
          else
                if (String.Compare(Convert.ToString(Session["Role"]), RolesEnum.Officer.ToString()) != 0)
                {
                    officersTasksRecived = tasks_to_officer_management.GetTasksToOfficers(id);
                    foreach (TasksToOfficer tt in officersTasksRecived)
                    {
                        DateTime dt = Convert.ToDateTime(tt.Date);
                        tasksList.Add(new CalendarDTO
                        {
                            id = tt.Id,
                            title = tt.Description,
                            start = ToUnixTimespan(dt),
                            end = ToUnixTimespan(dt),
                            url = ""
                        }
                        );
                    }
                }
            JsonResult resultToView = Json(tasksList);
            return Json(resultToView,JsonRequestBehavior.AllowGet);
        }

What should be the error ? In fact I am trying to attache the events on full calender control. I am picking up the records and building the JSon data in my action. but unable to show it on my calender. what I have to do ?

2 Answers 2

3

Just a guess here, but I think the problem is that you're JSON serializing the JsonResult instead of IList<CalendarDTO>. Instead of doing this:

  JsonResult resultToView = Json(tasksList);
  return Json(resultToView,JsonRequestBehavior.AllowGet);

Why don't you try this?

  return Json(tasksList,JsonRequestBehavior.AllowGet);
Sign up to request clarification or add additional context in comments.

Comments

0

Try getJson:

 $(document).ready(function () { 

    var officerid = document.getElementById('officerid').value;
    $.getJSON("/TasksToOfficer/Calender/" + officerid, function (data) {

        // do something with 'data'


        });

    });

You can point your browser to the action like this: http://yourdomain.com/TasksToOfficer/Calender/someID and see if you will get some data. Just replace 'someID' with some ID that exists.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.