我已经显示了此调度程序,但未绑定到任务。视图中的调度器。我使用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。