0

I am new to mvc3, developing my first project in mvc3. I have left side bar filled with top categories. On click of top category, I want to display sub categories under clicked category. Subcategories can be at any no of level.

  • How to go for it?
  • Should I use partial views?

On click of category, first I have to check if it has a subcategory, if yes then render sub categories.

tereško
  • 58,060
  • 25
  • 98
  • 150
Sanjivani
  • 283
  • 4
  • 11
  • In simple words you are trying to implement a tree view. Is it a dynamic or static treeview? – chamara May 03 '13 at 08:35
  • Check the link http://mikehadlow.blogspot.com/2008/10/rendering-tree-view-using-mvc-framework.html and http://weblogs.asp.net/raduenuca/archive/2011/04/24/asp-net-mvc-displaying-a-tree-view-using-a-recursive-declarative-helper-and-jquery.aspx – chamara May 03 '13 at 08:45
  • Thanks @chamara, since I am new in mvc field., those examples in the links I found bit difficult to follow. I think I will have to learn mvc at advance level first to implement tree view in my project :) – Sanjivani May 04 '13 at 13:32

1 Answers1

0

I think your best option here is to use AJAX and dynamic load of data.

On your javascript code bind the click event of your first level nodes to an AJAX call to a method on the server.

This method should: check if the node has children, if it has then return the list of children associated to it, if it hasn't it should return some info adverting your client code about it.

Your AJAX call on success should check if receive a list of subnodes or a message adverting that there's no subnodes. If it has the subnodes just append them to your html structure, if it hasn't do nothing (or whatever you want to do when clicking on a top node without children).

From here you can make your system grow in complexity as much as you want, using different methods for different node levels and behaviours, etc...

Bardo
  • 2,470
  • 2
  • 24
  • 42
  • Yes it is simple logic if we think in pure asp.net perspective. In asp.net mvc, I am trying to take advantage of its feature for this functionality, like partial views, sections. – Sanjivani May 04 '13 at 13:30