【问题标题】:Kendo UI Grid Update button not firingKendo UI Grid Update 按钮未触发
【发布时间】:2014-02-17 09:31:15
【问题描述】:

我正在使用 JavaScript 中的内联可编辑选项开发 KendoUI 网格,并且无法使更新按钮触发单击事件并将数据发布到服务器端更新事件。单击更新按钮甚至不会更新客户端上的网格。

希望有人能帮我指出我在这里做错了什么。

这不是重复的,因为我已经厌倦了答案中的 jfiddle 链接并且它也不起作用。 kendo UI grid update function wont fire

<div id="grid"></div>

 @section Scripts{

<script type="text/javascript">

    $(function () {
        var dataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url: "Home/GetPupilsAsJson",
                    dataType: 'json'
                },                    
                update: {
                    url: "Home/UpdatePupils",
                    dataType: 'json',
                    type: 'POST'
                }
            },
            pageSize: 5,
            autoSync: true                
        });

        $('#grid').kendoGrid({
            dataSource: dataSource,
            editable: "inline",
            pageable: true,
            columns: [{
                field: "Id",
                title: "Id",
                width: 150,
                hidden: true
            }, {
                field: "Firstname",
                title: "Firstname",
                width: 150
            }, {
                field: "Lastname",
                title: "Lastname",
                width: 150
            }, {
                field: "DateOfBirth",
                title: "DateOfBirth",
                width: 150
            }, {
                field: "Class",
                title: "Class",
                width: 150
            }, {
                field: "Year",
                title: "Year",
                width: 150
            },
            {
                command: ["edit"],
                width: 150
            }]
        });       
    });
</script>    
 }

家庭控制器

 public ActionResult GetPupilsAsJson()
    {            
        return Json(GetPupils(), JsonRequestBehavior.AllowGet);
    }

[AcceptVerbs(HttpVerbs.Post)]
    [HttpPost]
    public void UpdatePupils(Pupil p)
    {
          //never reach here
    }

【问题讨论】:

  • 您能否在 UpdatePupils 中尝试不使用参数 'Pupil p' 并告诉我程序是否到达那里?
  • @MustafaP .. 按照你的建议,我很累,但仍然无法正常工作。事实上,我的问题是更新按钮甚至没有关闭客户端上的编辑字段。我尝试使用 MVC 包装器,它工作正常,但不幸的是我们没有包装器的许可证。
  • 如果您的浏览器位于Developer Mode 或inspection 并检查网络流量,您是否看到任何请求,您看到请求通过了吗?我的意思是,您的浏览器是否在调用Home/UpdatePupils?
  • @OnaBai 没有来自 Kendo 的请求。

标签: asp.net-mvc kendo-ui kendo-grid


【解决方案1】:

我不知道为什么,但通过放置架构信息来修复它。

schema: {
        model: {
            id: "Id",
            fields: {
                Firstname: { editable: true, validation: { required: true } },
                Lastname: { validation: { required: true } },
                DateOfBirth: { validation: { required: true } },
                Class: { validation: { required: true } },
                Year: { validation: { required: true } }
            }
        }
    }

【讨论】:

  • 谢谢,如果你有一个剑道数据源对象,似乎你需要指定模式才能触发更新功能。
【解决方案2】:

使用@Url.Action("GetPupilsAsJson", "Home")',因此无需像BASEURL+ "Home/GetPupilsAsJson" 这样在更新操作中传递base url。

 var dataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url: '@Url.Action("GetPupilsAsJson", "Home")',
                    dataType: 'json'
                },                    
                update: {
                    url:'@Url.Action("UpdatePupils", "Home")',
                    dataType: 'json',
                    type: 'POST'
                }
            },
            pageSize: 5,
            autoSync: true                
        });

【讨论】:

【解决方案3】:

使用参数映射传递模型值

<script type="text/javascript">

    $(function () {
        var dataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url: '@Url.Action("GetPupilsAsJson", "Home")',,
                    dataType: 'json'
                },                    
                update: {
                    url: '@Url.Action("UpdatePupils", "Home")',
                    dataType: 'json',
                    type: 'POST'
                },
                parameterMap: function (options, operation) {
                   if (operation !== "read" && options.models) {
                      return { models: kendo.stringify(options.models) };
                       }
                }
            },
            pageSize: 5,
            autoSync: true                
        });

使用 parameterMap 调用控制器

public JsonResult UpdatePupils(string models)
        {

            return Json(..);
        }

【讨论】:

    【解决方案4】:

    您的任何单元格文本是否有 HTML 标签,如 &lt; 或 &gt;,删除它们并点击更新。将触发更新事件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-26
      • 1970-01-01
      • 2015-08-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多