View Full Version : TreePanel MVC onClick Node to Action

Mar 08, 2016, 10:24 AM

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:

m.ItemClick.Url = Url.Action("onClick");

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?

Mar 08, 2016, 3:01 PM
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 (http://examples4.ext.net/#/Events/DirectEvents/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 (http://forums.ext.net/showthread.php?60476&p=276580#post276580).

Hope this helps!

Mar 09, 2016, 2:51 PM

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)
X.Msg.Notify(new NotificationConfig
Icon = Icon.Accept,
Title = "Working",
Html = opcionMarcada

//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


return result;

With this code Works fine.

See you something strange or that can be done by another better way?

Mar 10, 2016, 7:29 PM
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. :)

Mar 15, 2016, 1:09 PM
Yes. Line 13 is only for test and didactic purposes.

Tanks for all.