TreePanel MVC onClick Node to Action

  1. #1

    TreePanel MVC onClick Node to Action

    Hello.

    I am using a TreePanel component and i have a problema to send to the action the id or name of the clicked node.

    The cshtml is like:

    X.TreePanel()
    .Width(300)
    .DirectEvents(m=>
       {
          m.ItemClick.Url = Url.Action("onClick");
       }
    )
    .Root(Model)
    I load the treepanel with the SiteMap:

    public ActionResult PruebasRoberto()
    {
    
        SiteMapNode siteNode = SiteMap.RootNode;
        Node root = new Node();
        root.Text = "Principal";
        root.AllowDrag = false;
        root.Expanded = true;
        ExtNetModel.LoadNodes(siteNode, root);
    
        return this.View(root);
    }
    and i need to know the clicked node text, description or something in the action "OnClick".
    But i don't know how pass it to the action.

            public ActionResult onClick(Node o)
            {
                return this.Direct();
            }
    Any Idea?
  2. #2
    Hello @sishco! Welcome to Ext.NET forums!

    I believe you are missing the "pass the parameter" step. Look at how extraParameters is used in this example: DirectEvent connecting to WebService.

    Here's an explanation on why you need to manually pass these parameters if you are asking yourself: Hidden controls not responding to directevent actions post #3.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Ok.

    The final solution:

    The cshtml is like:

    .DirectEvents(m =>
    {
          m.ItemClick.Url = Url.Action("onClick");
          // First the param "opcionMarcada"
          m.ItemClick.Before = "o.extraParams.opcionMarcada = record.data.text;"; //This one is because i need to send as parameter the text of the clicked node.
          // Second the param "tabPanelName"
          m.ItemClick.ExtraParams.Add(new {tabPanelName="TabPanel1" });
    }
    The controller code:

    
    public ActionResult onClick(string opcionMarcada, string tabPanelName)
    {
                //Notification
                X.Msg.Notify(new NotificationConfig
                {
                    Icon = Icon.Accept,
                    Title = "Working",
                    Html = opcionMarcada
                }).Show();
    
    
                //To open a View in another controller.
                string nombreVista="../Grid/GridView";
                //To open a View in the same controller.
                nombreVista = "VistaBase";
                
                //Opening a tab in the tabpanel with the name in tabPanelName.
                var result = new Ext.Net.MVC.PartialViewResult
                {
                    ViewName = nombreVista,
                    ContainerId = tabPanelName,
                    RenderMode = RenderMode.AddTo
                };
    
                this.GetCmp<TabPanel>(tabPanelName).SetLastTabAsActive();
    
                return result;
     }
    With this code Works fine.

    See you something strange or that can be done by another better way?
  4. #4
    Hello! Thanks for sharing the solution for you! It might be useful for other people in the future! We really appreciate it!..

    As for a better way, can't really say for sure without knowing the full case scenario but as far as I can read, the code looks good; assuming line 13 of the controller code you provided was left like that just for didactic purposes. :)
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Yes. Line 13 is only for test and didactic purposes.

    Tanks for all.

Similar Threads

  1. Replies: 2
    Last Post: Aug 10, 2015, 3:00 PM
  2. TreePanel node loaded: true to have node cached.
    By millenovanta in forum 2.x Help
    Replies: 0
    Last Post: Nov 28, 2013, 11:32 AM
  3. Replies: 11
    Last Post: Feb 06, 2013, 5:09 PM
  4. [CLOSED] Remote action refusal when moving a node
    By RCN in forum 2.x Legacy Premium Help
    Replies: 9
    Last Post: Jan 11, 2013, 10:32 AM
  5. TreePanel:Copying from one node to another node using drag and drop
    By eighty20 in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Jan 25, 2009, 7:48 AM

Posting Permissions