The following snippet gives me an error:
@foreach (PageViewModel root in menuData)
{
Action < PageViewModel > traverse = null;
traverse = (n) => {
@<text>
<li><a href="@n.Url">@n.Title</a></li>
</text>
n.Children.ForEach(traverse);
};
traverse(root);
}
The error is: CS1002: ; expected, right on the line after the </text> closing tag.
What am I doing wrong here?
You could try making your code snippet into a Templated Razor Delegate.
Based on Phil Haack’s example, you could make a helper that looked something like:
Disclaimer: I haven’t tested this and have conveniently omitted the call to
n.Children.Foreachfor simplification.