完整日历+事件+事件删除+ Ajax - 不发送日期值

时间:2011-07-15 00:37:15

标签: jquery .net asp.net-mvc asp.net-mvc-3 fullcalendar

我正在使用jquery full calendar,我试图在事件被删除时保存它。

   $('calendar').fullCalendar
            ({
                theme: true,
                defaultView: 'agendaWeek',
                columnFormat:
                {
                    week: "ddd"
                },
                header: false,
                allDaySlot: false,
                minTime: '6am',
                maxTime: '9pm',
                editable: true,
                droppable: true,
                drop: function (date, allDay)
                { // this function is called when something is dropped

                    // retrieve the dropped element's stored Event Object
                    var originalEventObject = $(this).data('eventObject');

                    // we need to copy it, so that multiple events don't have a reference to the same object
                    var copiedEventObject = $.extend({}, originalEventObject);

                    // assign it the date that was reported
                    copiedEventObject.start = date;
                    copiedEventObject.allDay = allDay;

                    // render the event on the calendar
                    // the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
                    $('calendar').fullCalendar('renderEvent', copiedEventObject, true);




                },
                eventDrop: function (event, dayDelta, minuteDelta, allDay, revertFunc, jsEvent, ui, view)
                {
                    var a = event.start;
                    var b = event.end
                    $.ajax
                    ({
                        url: MyURL,
                        type: 'Post',
                        data: { 'Start': a, 'End': b },
                        success: function (response)
                        {

                        }
                    });
                }
                )};

当我警告变量“a”& “b”它告诉我这些变量有时间。

  [HttpPost]
        public void CreateSlot(string Start, string End)
        {

        }

我知道它正在到达这个方法,但它从不发送任何参数,它们总是为空。

任何想法为什么?

修改

它似乎与物体或其他东西有关。我在drop方法中尝试了一下,看看是否发生了同样的事情并找到了相同的东西

然而,当我这样做时

 drop: function (date, allDay)
{
      $.ajax
                    ({
                        url: MyURL,
                        type: 'Post',
                        data: { 'Start': date.getTime() },
                        success: function (response)
                        {

                        }
                    });



}

没问题。所以我想知道asp.net mvc是否找不到绑定日期对象。当我使用字符串时,我觉得很奇怪。

2 个答案:

答案 0 :(得分:2)

将日期转换为C#支持的格式。

   eventDrop: function (event, dayDelta, minuteDelta, allDay, revertFunc, jsEvent, ui, view)
            {

                var a= $('#calendar').fullCalendar('formatDate', event.start, "yyyy-MM-dd HH:mm:ss");

                var b;

                if (event.end != null||event.end != undefined) {
                    b = $('#calendar').fullCalendar('formatDate', event.end, "yyyy-MM-dd HH:mm:ss");
                }


                $.ajax
                ({
                    url: MyURL,
                    type: 'Post',
                    data: { 'Start': a, 'End': b },
                    success: function (response)
                    {

                    },
                    error: function (msg) {
                        revertFunc();
                    },
                });


            },




 [HttpPost]
    public void CreateSlot(DateTime Start, DateTime End)
    {

    }

答案 1 :(得分:0)

是否有可能因为你没有将json列为ajax调用中的数据类型而没有以这种方式传递(因此你的方法没有正确获得parms)?

即,

$.ajax
     ({
       url: MyURL,
       type: 'Post',
       data: { 'Start': a, 'End': b },
       dataType: 'json',.....