0

create.jstreeの.bind内の$.ajax呼び出しでは、すべてが正しいようです。ただし、何らかの理由でコントローラー(MVC 3を使用しています)への呼び出しは発生していません。ajax呼び出しによって参照されるPOST関数にブレークポイントを設定しましたが、呼び出されることはありません。これにより、bindとajaxの呼び出しの組み合わせに問題があり、post関数が呼び出されないようになっていると思います。アドバイスをいただければ幸いです。

jstreeコード:

        $("#RequirementsTree")
    .bind("select_node.jstree", function(event, data) {
            if(is_requirement_node(data))
            {
                var id = data.rslt.obj.attr("id");

                if(id != null)
                {
                    $("#RequirementsTree").jstree('close_all')
                }
                else {
                    alert("Requirement node select error");
                }
            }
     })
    .bind("create.jstree", function(e, data) {
        alert(data.rslt.obj.text());
        alert(ParentNode);
        // Ajax call to Server with parent node id and new node text
        debugger;
        $.ajax({
            type: "POST",
            url: function(node) {
                return "/RMS/insertRequirementNode";
            },
            data: {
                    ParentID : ParentNode,
                    ChildNodeText : data.rslt.obj.text()
            },
            success: function(new_data) {
                return new_data;
            }   
        });
        ParentNode = null;
        if (data.rslt.parent == -1) {
            alert("Can not create new root directory");
            // Rollback/delete the newly created node
            $.jstree.rollback(data.rlbk);
            return;
        }
                BranchReqFLag = null;
    }).jstree({
        json_data: {
            data: RBSTreeModel,
            ajax: {
                type: "POST",
                data: function (n) {
                    return {
                        NodeID: n.attr("id").substring(4),
                        Level: n.attr("name").substring(7)
                    };
                },
                url: function (node) {
                    return "/Audit/GetRequirementsTreeStructure";
                },
                success: function (new_data) {
                    return new_data;
                }
            }
        },
        contextmenu: {
            items: function($node) {
                    return {
                        createItem : {
                            "label" : "Create New Branch",
                            "action" : function(obj) { this.create(obj); BranchReqFlag = "Branch"; ParentNode = obj.attr("id").substring(4);}
                        },
                        renameItem : {
                            "label" : "Rename Branch",
                            "action" : function(obj) { this.rename(obj);}
                        }
                    };
            }
        },
        plugins: ["themes", "json_data", "ui", "crrm", "contextmenu"]
    });

コントローラのPOST機能:

        [AllowAnonymous]
    [HttpPost]
    public int insertRequirementNode(int ParentID, string ChildNodeText)
    {
        RBSText CurrNode = new RBSText();
        int CurrentNodeID = -1;

        //CurrNode.RMSHierarchyText = ChildNodeText;
        using (Contract ActiveContract = getContract())
        {
            try
            {
                // Inserts the new node beneath the Parent Node
                CurrentNodeID = ActiveContract.CreateRMSNode(CurrNode, ActiveContract.ContractId, ActiveContract.user_id, 2, "Child");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        return CurrentNodeID;
    }
4

1 に答える 1

2

関数で指定されたURL$.ajax()が間違っている可能性があります。@Url.Content()サーバールートワイルドカードと一緒に使用し~ます。URLのプレフィックスとして、アプリケーションのデプロイ方法に関係なく、URLが常に正しいサーバールートパスを参照するようにします。これは、アクセスできるようにRazorビューでjstreeを設定していることを前提としています。かみそりエンジンへ:

   $.ajax({
        type: "POST",
        url: "@Url.Content("~/RMS/insertRequirementNode")",
        data: {
                ParentID : ParentNode,
                ChildNodeText : data.rslt.obj.text()
        },
        success: function(new_data) {
            return new_data;
        }   
    });

.jsファイルでjstreeを設定する場合は、最初にRazor Viewで定義されたjavascript変数にサーバールートを保存し、代わりにその変数を参照する必要があります。

于 2012-09-05T16:03:37.787 に答える