且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 AJAX 绑定时,具有 IEnumerable 属性的 Kendo Grid 模型在创建/更新后未正确更新

更新时间:2023-10-16 20:35:04

因此,如果将来有人偶然发现此问题,我联系了 Telerik 支持,他向我解释了:

So In case anyone stumbles on this in the future, I contacted Telerik support, who explained to me that:

dataSource 只支持值类型,不会序列化模型绑定器所需格式的数组.

The dataSource supports only value types and will not serialize the arrays in the format that is expected by the model binder.

他们还为我提供了一种解决方法,使用 request Data 函数调用 JavaScript 函数将数据转换为正确的格式.

They also provided me with a workaround using the request Data function to call a JavaScript function which converts the data into the correct format.

在视图中,通过指定要调用的 JavaScript 函数的名称来修改请求函数:

In the view, modify the request functions by specifying the name of the JavaScript function to call:

.Create(create => create.Action("AddNote", "ReleaseNotes").Data("serialize"))

然后添加进行转换的函数:

And then add in the functions which will do the conversion:

function serialize(data) {
    for (var property in data) {
        if ($.isArray(data[property])) {
            serializeArray(property, data[property], data);
        }
    }
}
function serializeArray(prefix, array, result) {
    for (var i = 0; i < array.length; i++) {
        for (var property in array[i]) {
            result[prefix + "[" + i + "]." + property] = array[i][property];
        }
    }
}