我如何从数据库中获得fullcalendar.js中的事件id



我将fullcalendar.js添加到我的asp.net MVC项目中。我可以在数据库中保存事件,我没有任何问题,但当我点击事件更新,我没有访问事件id更新数据库记录。我如何从数据库中获得事件id ?
js代码为:

function GetEvent() {
    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();
    var calendar = $('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        selectable: true,
        selectHelper: true,
        select: function (start, end, allDay) {
            //$('#modal-responsive').modal('show');
            document.getElementById("event-title").value = null;
            var title = null;
            $.ajax({
                url: "/Calender/ToPersian",
                type: 'Post',
                data: {
                    start: start,
                    end: end,
                },
                success: function (result) {
                    var startDate = result.SDate.substring(0, 11);
                    var startHour = result.SDate.substring(11, 23);
                    var endDate = result.EDate.substring(0, 11);
                    var endHour = result.EDate.substring(11, 23);
                    document.getElementById("fromDate1").value = startDate;
                    document.getElementById("field-4").value = startHour;
                    document.getElementById("toDate1").value = endDate;
                    document.getElementById("field-6").value = endHour;
                },
            });
            $(function () {
                $("#modal-event").dialog({
                    resizable: true,
                    height: "auto",
                    width: 800,
                    modal: true,
                    show: {
                        effect: 'fade',
                        duration: 350
                    },
                    hide: {
                        effect: 'fade',
                        duration: 50
                    },
                    buttons: {
                        "save": function () {
                            var title = document.getElementById("event-title").value;
                            var description = document.getElementById("field-3").value;
                            var startDay = document.getElementById("fromDate1").value;
                            var startHour = document.getElementById("field-4").value;
                            var endDay = document.getElementById("toDate1").value;
                            var endHour = document.getElementById("field-6").value;
                            //start = document.getElementById("fromDate1").value;
                            ////////////////////////////////////////////////////////
                            $.ajax({
                                url: "/Calender/ToGregorian",
                                type: 'Post',
                                async: false,
                                data: {
                                    start: document.getElementById("fromDate1").value + ' ' + document.getElementById("field-4").value,
                                    end: document.getElementById("toDate1").value + ' ' + document.getElementById("field-6").value,
                                },
                                success: function (result) {
                                    var mystart = result.SDate;
                                    var myend = result.EDate;
                                    start = mystart;
                                    end = myend;
                                }
                            });
                            ////////////////////////////////////////////////////////
                            if (title) {
                                $.ajax({
                                    url: "/Calender/Save",
                                    type: 'Post',
                                    data: {
                                        Title: title,
                                        Description: description,
                                        StartDay: startDay,
                                        StartHour: startHour,
                                        EndDay: endDay,
                                        EndHour: endHour
                                    }
                                });
                                calendar.fullCalendar('renderEvent',
                                    {
                                        title: title,
                                        start: start,
                                        end: end,
                                        allDay: allDay
                                       
                                    },
                                    true // make the event "stick"
                                );
                                $(this).dialog("close");
                                $('.fc-event-inner').attr({ 'data-start': start, 'data-end': end });
                                $('.fc-event-inner').uniqueId();
                            }
                            calendar.fullCalendar('unselect');
                            $(this).dialog("close");
                        },
                        "close": function () {
                            calendar.fullCalendar('unselect');
                            $(this).dialog("close");
                        }
                    }
                });
            });
        },
        editable: true,
        events: function() { 
            $.ajax({ 
                url: "/Calender/GetEventId", 
                type: 'POST', 
                data: { eventId:}, 
                success: function (doc) { 
                    events.push(doc); 
                    callback(events);
                } 
            }); 
        },
        
        ///////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////Update Event////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////
        eventClick: function (event, jsEvent, view) {
            var title = event.title;
            var EventStart = event.start;
            var EventEnd = event.end;
            var eventAllday = event.allDay;
            //document.getElementById("event-title").value=title;
            //document.getElementById("fromDate1").value = EventStart;
            document.getElementById("toDate1").value = EventEnd;
            $.ajax({
                url: "/Calender/ToPersian",
                type: 'Post',
                data: {
                    start: EventStart,
                    end: EventEnd,
                },
                success: function (result) {
                    var startDate = result.SDate.substring(0, 11);
                    var startHour = result.SDate.substring(11, 23);
                    var endDate = result.EDate.substring(0, 11);
                    var endHour = result.EDate.substring(11, 23);
                    document.getElementById("fromDate1").value = startDate;
                    document.getElementById("field-4").value = startHour;
                    document.getElementById("toDate1").value = endDate;
                    document.getElementById("field-6").value = endHour;
                },
            });
            $(function () {
                $("#modal-event").dialog({
                    resizable: true,
                    height: "auto",
                    width: 800,
                    modal: true,
                    show: {
                        effect: 'fade',
                        duration: 350
                    },
                    hide: {
                        effect: 'fade',
                        duration: 50
                    },
                    buttons: {
                        "save": function () {
                            //title = document.getElementById("event-title").value;
                            //start = document.getElementById("fromDate1").value;
                            ////////////////////////////////////////////////////////
                            $.ajax({
                             url: "/Calender/ToGregorian",
                                type: 'Post',
                                async: false,
                                data: {
                                    start: document.getElementById("fromDate1").value + ' ' + document.getElementById("field-4").value,
                                    end: document.getElementById("toDate1").value + ' ' + document.getElementById("field-6").value,
                                },
                                success: function (result) {
                                    var mystart = result.SDate;
                                    var myend = result.EDate;
                                    start = mystart;
                                    end = myend;
                                }
                            });
                            ////////////////////////////////////////////////////////
                            if (title) {
                                title = document.getElementById("event-title").value;
                                $.ajax({
                                    url: "/Calender/Save",
                                    type: 'Post',
                                    dataType: "Json",
                                    data: {
                                        Title: title,
                                        start: EventStart,
                                        end: EventEnd,
                                        allDay: event.allDay
                                //        Description: description,
                                //StartDay: startDay,
                                //StartHour: startHour,
                                //EndDay: endDay,
                                //EndHour: endHour
                                    }
                                });
                                event.start = start;
                                event.end = end;
                                event.allDay = event.allDay;
                                event.title = title;
                                calendar.fullCalendar('updateEvent', event);
                                //calendar.fullCalendar( 'refresh' );
                                $(this).dialog("close");
                                $('.fc-event-inner').attr({ 'data-start': start, 'data-end': end });
                            }
                            calendar.fullCalendar('unselect');
                            $(this).dialog("close");
                        },
                        "closeو": function () {
                            calendar.fullCalendar('unselect');
                            $(this).dialog("close");
                        }
                    }
                });
            });
        },
        editable: true
    });
};

eventClick回调的第一个参数是一个具有id属性的事件对象,因此您应该能够像这样访问它:event.id

相关内容

  • 没有找到相关文章

最新更新