Reputation:
I have a table department
with the following columns.
Id (P.K.)
Name
ParentDepartmentId (F.K. of same Department table)
Now I want to display all the data in hierarchical order using LINQ. something like this:
IT
.Net
Web Developer
Windows Developer
Java
PHP
Technical Support
OffLine
Online
Where IT has 3 sub dept .Net, Java, PHP. again .net has its own sub dept web developer and windows developer and so on.
How I can achieve this using LINQ. I am using ASP.Net MVC 3.0 using C#, Entity Framework etc.
Upvotes: 4
Views: 2309
Reputation:
Below are the link what exactly I wanted.
http://tpeczek.com/2010/01/asynchronous-treeview-in-aspnet-mvc.html
Upvotes: 1
Reputation: 13579
You can build a simple set of Html in your action code assign specific values of your HTML that you build dynamically in your Action with values you get by using linq. Then on you view when you return it using viewdata render it as pure html and use jquery to create the tree here some good example of jquery tree plugin
http://mbraak.github.com/jqTree/
Upvotes: 0
Reputation: 14935
Please see this link. It uses an extension Method .AsHierarchy()
to represent Hierarchical data
http://www.scip.be/index.php?Page=ArticlesNET18#AsHierarchy.
The returned object would be in tree structure. You just then have to decided on your presentation logic(space for each child node)
Upvotes: 0