views:

48

answers:

1

I am using fullCalendar and I'm able to populate the calendar with events very easily. And I undertsand the best way to add events to the calendar is through the database. What I need now is to catch and populate an edit event form after the user clicks an event.

How would I do this when I am using asp.net mvc 2?

A: 

Well I figured out a way that would work for me. In my aspx page here is the script to display the Calendar:

    <script type="text/javascript">
    $(document).ready(function() {
        $('#calendar').fullCalendar({
            events: "/Calendar/CalendarData"
        ,
            eventClick: function(event) {

                __doPostBack("EventPost_Clicked", event.id);
            }
        });
    });
</script>

The eventClick function part catches the id of the event and sends it back to my controller. Inside my controller:

    public ActionResult Calendar()
    {
        if (Request.HttpMethod == "POST")
        {
            if (Request.Form["AddEvent"] != null)
            {
                return RedirectToAction("AddEvent", "Calendar");
            }
            else if (Request.Form["__EVENTTARGET"] == "EventPost_Clicked")
            {
                string Eid = Request.Form["__EVENTARGUMENT"];
                return RedirectToAction("EditEvent", "Calendar", new {eventId = Eid });
            }

        }
        return View();
    }

The felse if catches the postback and would send it to an editevent page with the necessary event id.

I hope my struggle helps someone else.

DonWangugi