在 kendo 日程安排程序中保存约会后导航到另一个页面

Navigate to another Page after appointment has been saved in kendo scheduler

我已显示此调度程序但未绑定到任务。视图中的调度程序。我正在使用 java 脚本方法 read/create 调用网络 api

@(Html.Kendo().Scheduler<TaskViewModel> ()
.Name("AppointmentSearchScheduler")
.DataSource(dataSource => dataSource
.Custom()
.Schema(schema => schema
 .Model(m => {
  m.Id(f => f.TaskID);
  m.Field(f => f.OwnerID).DefaultValue(1);
 }))
.Transport(new {
 read = new Kendo.Mvc.ClientHandlerDescriptor() {
   HandlerName = "customRead"
  },
  create = new Kendo.Mvc.ClientHandlerDescriptor() {
   HandlerName = "customCreate"
  }
})))

下面是java脚本处理程序方法,为简洁起见,我不包括创建处理程序。

function customRead(options){
    //get the selected Row of the kendo grid
    var selectedRow = $("#locationgridKendo").find("tbody tr.k-state-selected");
    var scheduler = $("#AppointmentSearchScheduler").data("kendoScheduler")

    //get SelectedRow data
    var rowData = $('#locationgridKendo').data("kendoGrid").dataItem(selectedRow);

    if (rowData !== null) {
        //Convert data to JSON
        var rowDataJson = rowData.toJSON();
        //extract the location ID
        var locationId = rowDataJson.LocationID;          
        var CalenderweekStartDate = new Date().toISOString();
        baseUrl = $('base').attr('href');
        $.ajax({
            url: baseUrl + 'Schedular/api/GetAppPerLocation?locationId=' + locationId + '&date=' + CalenderweekStartDate,
            type: 'GET',
            cache: false,
            contentType: 'application/json',               
            success: function (result) {
//This method is hitting and i can see the data being returned
                console.log('data is received : ' + result.Data);
                options.success(result.Data);
            },
            error: function (xhr, status, error) {
                //alert("Error: Search - Index.js - submitAppointment()");
                var err = eval("(" + xhr.responseText + ")");
                alert(err.Message);
            }
        });

    }

}

这是通过 ajax 调用调用的网络 API 控制器。当我使用基本的 read/create 语法时,控制器工作得很好。 ajax 调用完成,它确实返回了成功方法和 returns 数据,但调度程序由于某种原因未绑定到传入数据。这是我的控制器代码

[HttpGet]
[Route("api/GetAppPerLocation")]
public DataSourceResult GetAppointmentPerLocation([ModelBinder(typeof(Usps.Scheduling.Web.ModelBinders.DataSourceRequestModelBinder))] DataSourceRequest request, int locationId, DateTime date) {

 List < TaskViewModel > locationAvailableAppointmentList = new List < TaskViewModel > ();
  locationAvailableAppointmentList = data.Select(appt => new TaskViewModel() {
   TaskID = appt.ServiceAppointmentId,
    Title = "Appointment Available",
    Start = DateTime.SpecifyKind(appt.AppointmentBegin, DateTimeKind.Local),
    End = DateTime.SpecifyKind(appt.AppointmentEnd, DateTimeKind.Local),
    Description = "",
    IsAllDay = false
  }).ToList();

 return locationAvailableAppointmentList.ToDataSourceResult(request);
}

由于某种原因,调度程序未绑定到传入数据。当我使用基本绑定方法但不使用传输时,传入数据完美运行。 我使用这种方法的目标是一旦我完成读取(调度程序现在没有绑定),在创建时我需要获取我的控制器返回的新创建任务的 ID,然后将该 ID 传递给另一个mvc 控制器呈现确认页面。强烈推荐实现此目标的任何其他方法。

如有任何错误,请原谅,因为这是我关于 Whosebug 的第一个问题。

My goal for using this approach is once i am done with read(scheduler is not binding now) , on create I need to grab the ID of the newly created task returned by my controller and then pass that id to another mvc controller to navigate render a confirmation page.

我推测读取没有返回正确的结果,所以我不得不修复它。另外,我的基本目标是在使用约会 ID 并显示确认屏幕后重定向到另一个页面。这是怎么完成的呢。我知道这不是最好的方法,但已经一年多没有人回答问题了。这是我采取的方法。

我在我的控制器中像这样向模型状态添加了一个错误

if (!String.IsNullOrEmpty(task.TaskID.ToString()))//redirect to confirmation page if the appointment was added to the queue
   ModelState.AddModelError("AppointmentID", confirmationNumber);

然后在客户端我像这样在网格上配置错误事件

.Events(
    events => events.Error("RedirectToConfirmationPage"))

这里是Javascript方法详情

function RedirectToConfirmationPage(e) {
        console.log('RedirecToConfirmationPage method......');
        console.log(e);
        if (e.errors) {
            var appointmentID = "";
            // Create a message containing all errors.
            $.each(e.errors, function (key, value) {
                console.log(key);
                if ('errors' in value) {
                    $.each(value.errors, function () {
                        appointmentID += this + "\n";
                    });
                }
            });
            console.log('Newly Generated AppointmentID  = ' + appointmentID);

            // Redirect URL needs to change if we're running on AWS instead of on local developer machines
            if (window.location.href.indexOf('/TestProject.Scheduling') > 1) {
                window.location.href = '/Scheduler/AppointmentConfirmation?confirmationNumber=' + appointmentID
            }
            else {
                window.location.href = '/Scheduler/AppointmentConfirmation?confirmationNumber=' + appointmentID
            }

        }
    }

希望对以后的人有所帮助。