views:

30

answers:

1

Hi, Trying to implement some nested loops that are spitting out good old nested html table data. So the question is; What is the best way to loop through lists and nested lists in order to produce easily maintainable code. It can get quite narly quite fast when working with multiple nested tables or lists. Should I make use of a HTML helper, or make something with the ViewModel to simplify this?

A requirement is if there are no children at a node there should be an empty row on that spot with some links for creation and into other parts of the system.

+1  A: 

Assuming you're working with nice strongly-typed data, I would go with a number of partial views to get this done. I did something similar with a project I worked on, and it made understanding the code and maintaining the code quite easy.

Robaticus
Interesting approach! Do you see any drawbacks with this? Performance drop or maintenance aspect - too many nested partial views might make it harder to follow the code. We have something like 5 tabs each tab is partial and inside those there are also partial jquery dialogues and even more partials for sections of the dialogues.
junior
You're probably going a bit further than I did with this from a complexity standpoint :) -- In thinking about how this is going to be rendered by the MVC engine, you might get a bit of a performance hit, as it's going to need to load the .ascx file for each of the individual partial views, but once they're loaded they should be cached, and it should perform just about as well as a single page. Regardless, I would think the performance hit would be in the minor milliseconds range and not noticeable to an end-user.
Robaticus
Yea, I have to agree, with the caching decoration on the partial view the performance shouldn't be that bad. Its worth the risk anyway :). I ended up passing System.Web.Mvc.ViewUserControl<IList<MySweetListOfThings>> as the strongly typed ViewModel and it works.
junior