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;
}