Recursive helper

Nov 23, 2013 at 10:11 AM
Hello, I want to traverse a tree in a template. So the model is smth like this:
class Model
{
public Node[] Nodes {get;set;}
}
and the node is:
class Node
{
public string Name {get;set;}
public Node[] Nodes {get;set;}
}
The model itself should not know how to render itself. I want to keep all rendering logic in a template to make it possible to change rendering without recompiling. So I came to the idea of a recursive helper. I thought I could write smth like this in a template header:
helper Render(Node node){
 <text>node.Name</text>
 foreach(var childNode in node.Nodes){
 Render(childNode);
}
}
and later use it to render a model:
<div>
@foreach(var node in @Model.Nodes){
@Render(node)
}
</div>
Unfortunately I could not compose a template that would compile without an error. Is it possible to use helpers recursively? Can anybody provide a sample how to implement recursive helper correctly?