Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I want to delete an event in fullcalendar. I can delete the event, but only after refresh page the user sees that the event is deleted. so if the user press on delete the event is still vissible after the delete method.And also the event is deleted from the database

I have this:

C#
var dataRow = {
               'Id': EventID

           }
           $.ajax({
               type: 'POST',
               url: "/Calendar/DeleteEvent",
               dataType: "json",
               contentType: "application/json",
               data: JSON.stringify(dataRow),
               async: true,
               processData:false,
               cache:false,
               success: function (data) {
                   alert(data);
                   $('#calendar').fullCalendar('refetchEvents');

                   },
                   error:function(xhr){
                       alert('error');
                   }
           });

       }


the strange thing is also that every time after delete is pressed,

C#
error:function(xhr){
                        alert('error');
                    }


will be hitted.

Thank you

Oke

this is my button click of delete:


C#
eventClick: function (calEvent, jsEvent, view) {





                    //alert(calEvent.start);
                    $('#btnPopupDelete').click(function () {

                        var id = calEvent.id;

                        DeleteEvent(id)
                        $('#popupEventForm').hide();


                    });


and this are my delete methods:

C#
public static bool DeleteEvent(int Id)
        {
            try
            {
                LolaBikeContext db = new LolaBikeContext();
                AppointmentDiary diary = db.AppointmentDiarys.Find(Id);
                if (diary == null)
                {
                   return HttpNotFoundResult();
                }
                db.AppointmentDiarys.Remove(diary);                
                db.SaveChanges();
            }
            catch (Exception)
            {

                throw;
            }
                        return true;


        }


and the delete controller action:

C#
public bool DeleteEvent(int Id)
        {
            return DiaryEvent.DeleteEvent(Id);
        }
Posted
Updated 17-Mar-15 1:57am
v4
Comments
Sergey Alexandrovich Kryukov 17-Mar-15 6:39am    
The term "event" is ambiguous. At first, I've been confused: if it was the event, as it is understood in programming, such as DOM element event, there is no such concept as "delete event".
But probably you mean the elements of FullCalendar schedule. Isn't it http://fullcalendar.io? http://plugins.jquery.com/fullcalendar? You have to make it clear what you are talking about...
—SA
[no name] 17-Mar-15 6:41am    
?? where you talking about
Sergey Alexandrovich Kryukov 17-Mar-15 6:50am    
I explained be editing my comment above, please see. I've been confused; you need to make things clear... Will you use "Improve question" and explain things in more detail?
—SA
[no name] 17-Mar-15 6:55am    
You can delete a event, but only after postback the event will be not seen anymore on the calendar. And the ajax call is hitting every time the error alert - very clear. And in my header I use the word Fullcalendar!!
Sergey Alexandrovich Kryukov 17-Mar-15 7:01am    
This is rude. I advise you not to talk to people like that, otherwise who would like to help you?

If I was confused, someone else could be confused. I advise you to improve the answer. You are the one who is interested in that, not me. If you don't want to improve it, feel free to leave it as is.

—SA

1 solution

This is the way the web works. You aren't constantly connected to the database so you have to refresh the page to see changes in the database. Or, you have to write code to also remove it from the Calendar.
 
Share this answer
 
Comments
[no name] 17-Mar-15 8:56am    
ok, but why the ajax call hits only the error and not the succes, then a refresh is not required. Because I have this:alert(data);
$('#calendar').fullCalendar('refetchEvents');
ZurdoDev 17-Mar-15 9:00am    
You're asking 2 more questions so I'll address them separately.

1. If it hits the error only you can know why. You'll need to debug it and find out what the error is. I recommend referring to http://api.jquery.com/jquery.ajax/ because the error function can receive 3 parameters. Find out what the error is.

2. I have no idea what calendar you are using. You say it is called FullCalendar and perhaps there is only 1 control in the whole world named that, but I don't know. If it supports a "refresh" of events by calling refetchEvents then do that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900