简体   繁体   English

asp.net mvc ajax发布传统参数序列化

[英]asp.net mvc ajax post traditional parameter serialization

I'm using kendo-ui's treeview. 我正在使用kendo-ui的treeview。

I need to refresh the treeview after inserting a new treenode. 插入新的treenode之后,我需要刷新treeview。 For the sake of user friendliness, I want to make the treeview to auto expand to the newly created treenode by giving three parameters to the method responsible for creating the treeview's JSON. 为了方便用户使用,我想通过给负责创建树视图JSON的方法提供三个参数,使树视图自动扩展到新创建的treenode。 You can see the code for that below. 您可以在下面查看该代码。

treeview.dataSource.transport.options.read.data = {
    showInactiveItems: $("#ShowInactiveAreas").find('i').hasClass('icon-eye-close'),
    selectedAreaId: areaId,
    selectedAreaType: areaType,
    ancestry: ancestry
};
treeview.dataSource.read();

So I am planning to pass array of parent IDs (ancestry) to the method so that the method knows which one to set the expand property to true. 因此,我计划将父ID(祖先)数组传递给该方法,以便该方法知道将expand属性设置为true的方法。

If it was a jQuery I know how to do that with jQuery.makeArray(ancestry) and set the traditional parameter serialization to true in the $.ajax(). 如果是jQuery,我知道如何使用jQuery.makeArray(ancestry)并在$ .ajax()中将传统参数序列化设置为true。 But this is kendo. 但这是剑道。

Does anyone know how to make the treeview.dataSource.read() to do traditional param serializing? 有谁知道如何使treeview.dataSource.read()进行传统的参数序列化?

Or how to make asp.net mvc 4.0 to accept ajax post parameter such as 或者如何使asp.net mvc 4.0接受ajax发布参数,例如

ancestry[]  Indonesia
ancestry[]  Aceh

It seems asp.net MVC doesn't support "[]" in parameter names unlike PHP. 好像asp.net MVC不像PHP那样在参数名称中不支持“ []”。

It seems that I cannot insist to post data. 看来我不能坚持要发布数据。 I have to switch method to use urlencoded parameter using jQuery.param 我必须使用jQuery.param切换方法以使用urlencoded参数

    treeview.dataSource.transport.options.read.data = {
            showInactiveItems: $("#ShowInactiveTerritories").find('i').hasClass('icon-eye-close'),
        selectedTerritoryId: territoryId,
        selectedTerritoryType: territoryType,
    };
    query = "?" + jQuery.param({ ancestry: ancestry }, true);
    treeview.dataSource.transport.options.read.url = loadurl + query;
    treeview.dataSource.read();

Worked! 工作了!

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

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