Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3959814
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:46:35+00:00 2026-05-20T02:46:35+00:00

I am using jsTree to display a tree structure of hierarchical data within my

  • 0

I am using jsTree to display a tree structure of hierarchical data within my ASP.NET MVC application. So far, I am able to access the data (through a controller method which returns JSON data) and display the tree. I am also able to select nodes in the tree and that works correctly. Here is the jsTree code for doing this:

$('#tree').
    bind('select_node.jstree', function(event, data) {
        alert("Node is selected.");
    }).
    jstree({
        "core": {},
        "json_data": {
            "ajax": {
                type: 'POST',
                url: '/Scenario/TreeData',
                data: "id=" +  <%= Model.Scenario.ScenarioID %>,
                success: function(data, textStatus, xhr) {
                    if(data.failed) {
                        window.location.href = data.redirectToUrl;
                    }
                }
            }
        },
        "themes": {
            "theme": "default",
            "dots": true,
            "icons": true
        },
        "ui": {
            "select_limit": 1
        },
        "plugins": ["themes", "ui", "json_data"]
    });

Here is my TreeData action:

[HttpPost]
public ActionResult TreeData(int id)
{
    var tree = new JsTreeModel();

    Scenario scenario = repository.GetScenario(id);
    if (scenario != null)
    {
        tree.data = new JsTreeData();

        // [snip] Do the work to build the tree. [/snip]

        return Json(tree);
    }

    var jsonData = new
    {
        failed = true,
        redirectToUrl = Url.Action("NotFound")
    };
    return Json(jsonData);
}

Where I am getting stuck is, once I click on a node, I am unsure of how to retrieve the data for that specific node from my application (via the Controller), display it (presumably in a partial view – all of which I have created at this time – strongly-typed partial views), and then offer the option to submit that partial view back to the server to update the data.

I’m not really sure where to begin. One thought I had is to expand my TreeModel class (C# model which makes it easier to build the JSON data for the tree) to take more parameters in the “data” value which may allow me to know which model I am attempting to retrieve. However, this doesn’t seem that elegant.

Am I missing something obvious? Does anybody have any other suggestions? Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T02:46:36+00:00Added an answer on May 20, 2026 at 2:46 am

    I ended up figuring this out and wanted to share in case anybody else wants to do the same thing.

    I first bound the select_node.jstree event to my tree and then built the tree (all done client-side, of course).

    $('#tree').
    bind('select_node.jstree', function(event, data) {
        var id = 1; // TODO - Get the ID from the current model.
        var url = data.rslt.obj.children("a:eq(0)").attr("href");
        $.ajax({
            type: 'POST',
            url: '/Scenario/' + url,
            data: 'id=' + id,
            success: function(data) {
                $('#ajaxcontent').html(data);
            }
        });
    }).jstree({
        "core": {},
        "json_data": {
            "ajax": {
                type: 'POST',
                url: '/Scenario/TreeData',
                data: "id=" + <%= Model.Scenario.ScenarioID % > ,
                success: function(data, textStatus, xhr) {
                    if (data.failed) {
                        window.location.href = data.redirectToUrl;
                    }
                }
            }
        },
        "ui": {
            "select_limit": 1
        },
        "plugins": ["themes", "ui", "json_data"]
    });
    

    Notice that I am grabbing the URL value from the node. I had to change my JsTreeModel so that I could change the href value on the node. (JSON data representation is – data.attr.href) I set this value when I build my Scenario. Each node has its own URL. (I am passing the ID parameter in, so I can retrieve the correct Scenario server-side. That may or may not be necessary depending on your needs.)

    I then create an action for each URL in my Controller. I do what I need to do with the data, and then return it back to the page (via the AJAX call shown previously). It’s actually a fairly simple solution now that I know what I am doing. But, due to a bit of lack of documentation, it was a bit tricky to first figure out.

    Hope this can help someone else!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using JSTree with ASP.net. The html generated for the tree looks like
I've got a JTree which I'm using to display some (unsurprisingly) hierarchical data. Part
I want to write an application using jsTree that would display and manipulate directory
Greetings, I am using jsTree to generatate my hierarchical data. JsTree is generated as
Using C# for ASP.NET and MOSS development, we often have to embed JavaScript into
I am using jstree to build a tree menu. When you select an item
I'm using jsTree and I need to convert this HTML tag tree code <ul>
I am using jstree and several nodes in my tree have the same name.
Using jsTree, when adding a node to my tree using the create_node function, I
Using jsTree, I get data.rslt undefined when trying to read the data object. Here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.