【问题标题】:Full Calendar + Event + Event Drop + Ajax - Does not send date values完整日历 + 事件 + 事件删除 + Ajax - 不发送日期值
【发布时间】:2011-07-15 00:37:15
【问题描述】:

我正在使用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是否找不到绑定日期对象。当我使用字符串时,我觉得很奇怪。

【问题讨论】:

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


    【解决方案1】:

    将日期转换为 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)
        {
    
        }
    

    【讨论】:

      【解决方案2】:

      是否有可能因为您没有在 ajax 调用中将 json 列为数据类型,所以它没有以这种方式传递(因此您的方法没有正确获取参数)?

      即,

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

      【讨论】:

      • 我可以试试(怀疑,因为我都是这样做的)
      • 我可能对此有误,但我认为您需要在“a”和“b”周围加上引号。例如: data: { 'Start': '"' + a + '"', 'End': '"' + b + '"' },因为它确实是一个字符串,它需要引号json 请求。 date.getTime() 返回一个数字,因此不需要引用。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-04
      相关资源
      最近更新 更多