Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,

I want to delete an event of the full calender,

I have this:

C#
$('#btnPopupDelete').click(function () {
           
            
            function DeleteEvent(EventID) {

                var dataRow = {
                    'Id': EventID


                }

                $.ajax({
                    type: 'POST',
                    url: "/Calendar/DeleteEvent",
                    dataType: "json",
                    contentType: "application/json",
                    data: JSON.stringify(dataRow)
                });

            }
        });


this in the CalenderController:

C#
public bool DeleteEvent(int Id)
       {
           return DiaryEvent.DeleteEvent(Id);
       }


and this in the DiaryEvents:

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


            return true;
        
        
        }


this the button:

C#
<button type="button" id="btnPopupDelete" data-dismiss="modal" class="btn btn-danger right ">Delete event</button>


But it doesnt hit the Controller

Thank you
Posted

Hi

Please try like below:

JavaScript
$('#btnPopupDelete').click(function (e) {
       var id = 100 //for test
       DeleteEvent(id)
   });
   function DeleteEvent(EventID) {
       var dataRow = {
           'Id': EventID
       }
       $.ajax({
           type: 'POST',
           url: "/Calendar/DeleteEvent",
           dataType: "json",
           contentType: "application/json",
           data: JSON.stringify(dataRow)
       });

   }



Regards
Dominic
 
Share this answer
 
Comments
Sinisa Hajnal 29-Jan-15 6:42am    
You have more good will then I do :)
[no name] 29-Jan-15 6:45am    
Thank you Domic!!
[no name] 29-Jan-15 7:55am    
Just one question, what is then the actual id, I try it like this: var EventID = $("#Id").val(). I mean how to get the actual Id?
[no name] 29-Jan-15 9:16am    
If I do it like this: eventClick: function (calEvent, jsEvent, view) {
alert(calEvent.id) I see the id.
but this doesnt work: $('#btnPopupDelete').click(function (e, calEvent) {
var id = calEvent.id;
alert(id);

DeleteEvent(id)
//$('#popupEventForm').hide();
});
You should move function DeleteEvent outside of scope{} of the click

Instead do this:

function DeleteeVent (eventId) {}

$().click( function () { DeleteEvent(id) });

If this helps please take time to accept the solution. Thank you
 
Share this answer
 
Comments
[no name] 29-Jan-15 6:24am    
Like this?

function DeleteEvent(EventID) {

var dataRow = {
'Id': EventID


}

}
$('#btnPopupDelete').click(function () {
$('#popupEventForm').hide();



$.ajax({
type: 'POST',
url: "/Calendar/DeleteEvent",
dataType: "json",
contentType: "application/json",
data: JSON.stringify(EventID),
async: true,
cache: false,
success: function (response) {
if (response == 'True') {
$('#calendar').fullCalendar('refetchEvents');
alert('event deleted!');
}
else {
alert('Error, could not save event!');
}
}

});


});

but what has to be: data: JSON.stringify(EventID),

this doesnt work
Sinisa Hajnal 29-Jan-15 6:41am    
No, I everything goes into DeleteEvent, and in the click event you only call the function with given ID. See Dominics solution, he did in code what I described in shorthand.
[no name] 29-Jan-15 7:34am    
Thank you but what is then the actual value, I try it like this: var id = $("#Id").val()
Sinisa Hajnal 29-Jan-15 7:56am    
Since you didn't offer any info on the structure or presentation of your data, I honestly cannot say. However you select your id, pass it into the function and you're done. But that is something you have to know, it is your system.
[no name] 29-Jan-15 7:58am    
It is Id. but is the syntax correct? .val?

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