views:

186

answers:

2

Hello, I am preparing a skeleton of ASP.NET MVC application with basic CRUD functions on Products and Parts included in these products. Application contains couple of strongly-typed views based on the MasterPage and now I want to add a widget to display the menu tree. This menu tree is going to reflect the Products/Parts structure so it is related to the content displayed in the main window.

I have searched forums and found different ways of tree rendering and including the new widget in the application:

  • jquery.treeview - provides nice-looking tree but how can I use (build, render, pass to the view) it in my application?
  • RenderPartial, RenderAction, etc.- seems to be very clear so I was going to use RenderAction method to include my widget in the master page, but how can I build/render the tree to be displayed?
  • extend the HtmlHelper to create a new Html.RenderTree method (nice example at: http://www.matthidinger.com/archive/2009/02/08/asp.net-mvc-recursive-treeview-helper.aspx)

Probably I should just merge some fragments of found examples but since I am new to ASP.NET MVC technology I am not sure about the best pattern in such case.

Any help (suggestions, patterns, point the good example, etc.) would be appreciated.

Thanks
diork

A: 

You can use jqGrid to display tree. It also has CRUD operations support. Not that it's extremely easy to use.

queen3
A: 

I'd probably use the existing HtmlHelper tree rendered unless you needed fancy UI support.

If you do want to use a javascript version all you'd need to do is wrap everything up in a Action or partial View to call from your master page.

Getting the data is going to be the more difficult part because of MVC's lack of partial rendering or sub controllers.

You could use a technique like this: http://stackoverflow.com/questions/1570127/render-partial-view-using-jquery-in-asp-net-mvc

For more information check out MvcContrib and their sub-controller functionality and while your at it, take a look at: http://devlicio.us/blogs/derik%5Fwhittaker/archive/2008/11/24/renderpartial-vs-renderaction.aspx for more information to help you decide between RenderAction and RenderPartial.

IMO I'd avoid rendering via master page at all costs though. You'll have to get into masterviewmodels and if you want strongly typed master pages there is a lot of invasive cruft code that has to be added to your MVC application.

jfar