【问题标题】:Kendo UI Scheduler Edit pop up window wont close after making changes进行更改后,Kendo UI Scheduler Edit 弹出窗口不会关闭
【发布时间】: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


    【解决方案1】:

    Kendo 需要在你的参数映射中返回一个有效的 JSON 格式,所以你可以试试这个:

            parameterMap: function(options, operation) {
                if (operation !== "read" && options.models) {
                    return {models: JSON.stringify(options.models)};
                }
                return {};
            }
    

    也许this Link 也能帮到你……

    (复制只是为了防止死链接)

    新版本的 jQuery 有一个重大变化,影响到 Kendo Q1 2013 版本 2013.1.319

    由于更新和销毁请求在服务器端一切正常执行的情况下从服务器返回空结果,因为空结果不是有效的JSON,所以触发了dataSource的错误事件。

    使用 MVC 扩展时建议的解决方案是: 使用最新的内部构建版本 2013.1.327 将 Update/Destroy 操作的响应从仅序列化 ModelState 更改为:

    return Json(ModelState.IsValid ? new object(): ModelState.ToDataSourceResult());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多