【发布时间】:2014-03-20 19:20:17
【问题描述】:
我正在试用 Kendo UI HTML 调度程序。 我能够通过我的 ASP.NET MVC 应用程序成功地从数据库中读取约会。
对于读取:我正在从我的 ASP.NET 控制器发送 JsonResult。
对于更新:控制器正在获取一个 URL JSON 编码字符串,我对它进行反序列化并更新数据库,并且不向调用者返回任何内容。
打开要编辑的事件时,进行更改并按“保存”。控制器被调用并更新记录,但弹出窗口既不关闭也不更新调度程序。
Telerik 网站上的 HTML 演示在更新时返回“callback()”并且工作正常,但是我的代码中缺少什么会使更改反映出来。
**view**
<script>
$("#scheduler").kendoScheduler({
// configuration //
dataSource: {
batch: true,
transport: {
read: {
url : "http://localhost/Scheduler/Appointments",
dataType: "json"
},
update: {
Type:"POST",
url: "http://localhost/Scheduler/UpdateAppointment",
dataType: "json"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: JSON.stringify(options.models)};
}
}
},
schema: {
model: {
// my model
}
},
</script>
控制器 公共 JsonResult UpdateAppointment(字符串模型) {
if (models != null)
{
char[] charsToTrim = { '[', ']' };
string model_Trimmed = models.Trim(charsToTrim);
// Deserialize
Appointment SerializedAppointment = new JavaScriptSerializer().Deserialize<Appointment>(model_Trimmed);
Models.Entities.Appointment AppointmentToUpdate = db.Appointment.Where(x => x.TaskID == SerializedAppointment.TaskID).Single();
AppointmentToUpdate.Title = SerializedAppointment.Title;
AppointmentToUpdate.Start = SerializedAppointment.Start;
AppointmentToUpdate.End = SerializedAppointment.End;
db.SaveChanges();
}
return new JsonResult() {Data=null, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
【问题讨论】:
标签: c# asp.net asp.net-mvc json telerik