2016-06-19 17 views
1

我已经显示了此调度程序,但未绑定到任务。视图中的调度器。我使用Java脚本方法来读取/创建调用网页API在约会已保存在kendo调度程序后,导航到另一个页面

@(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" 
    } 
}))) 

下面是JavaScript处理方法,我不包括为简洁创建处理程序。

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调用的Web API控制器。当我使用基本的读取/创建语法时,控制器完美工作。 ajax调用完成,它确实返回成功方法并返回数据,但由于某种原因调度程序未绑定到传入数据。这是我的控制器代码

[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控制器来呈现一个确认页面。任何其他方法来完成这一目标将被强烈建议。

请原谅我的任何错误,因为这是我的第一个问题在stackoverflow。

回答

0

我使用这种方法的目标是,一旦我与读取(调度器现在不绑定)完成后,上创建我需要抓住我的控制器返回的新创建的任务的ID,然后通过该id到另一个mvc控制器导航渲染确认页面

我推测阅读没有返回正确的结果,所以我不得不解决这个问题。我的基本目标是在约会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 
      } 

     } 
    } 

希望它对于路上的某个人有帮助。

相关问题