我无法弄清楚这段 Razor 代码的问题所在。
IDE 告诉我,我的第一个 <ul>
没有匹配的结束标记。它还说,结束标记没有匹配的开始标记。此外,它还将几行代码识别为普通文本,而不是 C# 代码。
IDE 对有问题的行进行了注释。
<div class="list-container">
@{
int i = 0;
<ul> //no matching ending tag
@foreach (var item in Model.Items)
{
if (i % 8 == 0)
{
</ul> //no matching start tag
<ul> //"Text is not allowed between the opening and closing tags for element ul"
} //IDE doesn't recognize this closing brace as code... see it as text
<li>@item.ContentItem.Title.Value</li>
i++; //IDE doesn't recognize this closing brace as code... see it as text
} //IDE doesn't recognize this closing brace as code... see it as text
</ul>
}
</div>
当视图执行时,我得到了预期的编译错误,因为您忘记了一个
}
: "代码块缺少闭合 "}" 字符。"。一旦我从
if
语句内部删除 </ul><ul>
,视图就可以编译和执行了。有趣的是,当我点击其中一个
ul
标签时,正确的起始或结束标签也会被突出显示。显然我做错了什么。难道我没有正确使用 Razor 吗?
foreach
和if
),并在关闭的</ul>
标签之前没有将它们关闭。因此,关闭的</ul>
标签在与if(i % 8 == 0)
开始的同一代码块中没有相应的开放标签。 - Floremin