简体   繁体   English

在Ajax调用中传递kendo网格模型

[英]Pass kendo grid model in Ajax call

I need to pass kendo grid model (on save event) to the server side in an ajax call. 我需要在ajax调用中将kendo网格模型(在保存事件中)传递到服务器端。 How can i do that? 我怎样才能做到这一点? Tried the following 尝试了以下

function onSave(e) {

var keys = Object.keys(e.values);
    var colName = keys[0];
    var alignment;
    var mapHeaderId = $('#ddlMaps').val();
    var yearId = $('#ddlYear').val();

$.get("@Url.Action("CalculateFormattingForResult", "Maps")", { studentId: e.model.studentid, colId: colName, value: e.values[colName], mapHeaderId: mapHeaderId, yearId: yearId,
                                                                    model: JSON.stringify(e.model)
    }, function (data) {}
}

My C# code is 我的C#代码是

public string CalculateFormattingForResult(int studentId, string colId, string value, int mapHeaderId, int yearId, string model) {
}

If someone is interested into why i am doing that..is because i need to get the latest edited values in the grid based on which i have to calculate/update other values in the grid. 如果有人对我为什么这样做感兴趣..是因为我需要获取网格中最新的编辑值,因此必须根据该值来计算/更新网格中的其他值。

UPDATE UPDATE

I tried it with $.post and it worked but with post the problem is that probably i can only submit the form once however, i am only doing data validation on edit event of each cell...so i need to do it again and again. 我用$ .post尝试了一下,它起作用了,但是用post的问题是,我可能只能提交一次表单,但是,我只对每个单元格的edit事件进行数据验证...所以我需要再次做一次,再次。 so my question is still there... how do i pass json string which is [kendo dataItem (row)] in ajax?? 所以我的问题仍然存在...我如何在ajax中传递[kendo dataItem(row)]的json字符串?

The problem was i had to put a $.post instead of $.get..found answer here: passing json in ajax 问题是我不得不在这里放置$ .post而不是$ .get..found答案: 在ajax中传递json

Also, as I mentioned in update, second time kendo grid model changes like this 另外,正如我在更新中所述,第二次剑道网格模型会像这样更改

originaljson + edited values as json originaljson +编辑后的值作为json

for example: firstname:"samra", surname:"abc" becomes firstname:"samra", surname:"abc" , firstname:"sarah", surname:"xyz" 例如: firstname:“ samra”,姓氏:“ abc”变为firstname:“ samra”,姓氏:“ abc”,firstname:“ sarah”,姓氏:“ xyz”

In my case the newer values contained html divs (to format cells), so it was not getting posted!. 在我的情况下,较新的值包含html div(用于格式化单元格),因此不会被发布!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM