【发布时间】:2012-11-02 13:32:25
【问题描述】:
我使用 Razor Generator 创建了一个模板。现在我需要在一个递归函数中创建一个嵌套的项目列表。我试过this solution,但后来我所有的代码都被标记为错误。
@* 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>
}
添加助手后我得到的一些不相关的错误:
-Error 3 Invalid expression term ';'
Error 4 Feature 'lambda expression' cannot be used because it is not part of the ISO-2 C# language specification
Error 13 Feature 'implicitly typed local variable' cannot be used because it is not part of the System C# language specification
Error 6 The name 'WriteLiteralTo' does not exist in the current context
但是当我删除辅助方法时,所有这些都消失了!
是我做错了什么还是无法在 Razor 模板中创建助手?
【问题讨论】:
-
你遇到了什么错误?
-
@Bobson :我在问题中添加了错误
-
我很困惑。尝试删除
ShowTree()周围的@{ },因为您已经在代码块中。 -
@Bobson : 如果我删除 @{} 那么该行也会被标记为错误!
标签: c# razor html-helper razorgenerator