开发者

ASP.Net MVC - Build a load on demand TreeView

开发者 https://www.devze.com 2022-12-16 21:03 出处:网络
I am wondering how to build a load on demand tree view using ASP.Net MVC.I understand what is involved in creating a JQuery TreeView using lists, but the load on demand part is really confusing me.I d

I am wondering how to build a load on demand tree view using ASP.Net MVC. I understand what is involved in creating a JQuery TreeView using lists, but the load on demand part is really confusing me. I don't need the full solution, but can somebody point me in the right direction on where I should start?

I have done these plenty of times using WinForms which keeps the view state preserved. One of the issues I am seeing is remembering all the node that have been expanded an开发者_C百科d not just the newly expanded one.

If anyone had some advice, I would appreciate it. Thanks!


You'll need to find a treeview jquery plugin that will work for you, then bind that to a controller in MVC that can behave the way you're looking for.

Make sure your html is rendering out the placeholder for the children (or that the jQuery plugin knows how to add the children on its own).

You'll have to either provide the treeview an url with a specific set of parameters, or respond to event handlers and make calls to get children.

When looking for a treeview plugin, your life will be easier if you find one that supports the async loading of child nodes.

If you had to roll your own, you might have a div with an ID of ChildNode-1 and the call might look something like the following in MVC:

$("#ChildNode-1").load("/[your_controller]/GetNode", {nodeId:1});

On your controller you would have a method called GetNode that returns a PartialViewResult. It would accept a parameter of type int called nodeId. Mark it with the attribute [HttpPost]. jQuery wizardry handles the post action and MVC magic and reflection take care of the rest. Your PartialViewResult would also have to return more nodes formatted to make more submissions per the above.

Cheers, -jc

0

精彩评论

暂无评论...
验证码 换一张
取 消