I am creating a .NET MVC application and I have a view in which I want to display the following:
Category
and then a list of items for the current category
[possibly] followed by a list of subitems for the current item
I could create my own ViewModel class that will send 3 separate IEnumerable lists (categories, items and sub-items). The problem with this approach is that there is no easy way to display data in the correct order (hierarchy) in the view. With this approach, I would have three lists, and then I would need to add conditional logic during rendering. This would mean that each list of elements would be repeated several times when I try to stack the elements in the corresponding positions on the page.
I would rather pass the data in the correct order, perhaps as an XML file. What is the right approach?
I also considered the possibility of concatenating the data in the controller and passing the formatted text to the view, but this seems to violate the idea of rendering the view descriptor.
source
share