I created a template using the Razor Generator . I now need a recursive function to create a nested list of items. I tried this solution , but then all my codes became marked as errors.
@* Generator: Template *@ @functions { public IList<Models.Category> Topics { get; set; } } @helper ShowTree(IList<Models.Category> topics) { <ul> @foreach (var topic in topics) { <li> @topic.Title @if (topic.Childs.Count > 0) { @{ ShowTree(topic.Childs); } } </li> } </ul> }
Some of the irrelevant errors I received after adding the helper:
-Error 3 Invalid expression term ';' Error 4 Feature 'lambda expression' cannot be used because it is not part of the ISO-2 C
but when I remove the helper method, it all just disappears!
Am I doing something wrong or is creating helpers in Razor templates impossible?
source share