更新时间:2023-01-14 16:57:59
有这里有两个问题:
&LT的presence感生成XML类标记(如HTML);标签>
确定code和标记之间的过渡。你也许可以用它来生成任何文本,但你可能会遇到的问题时,你的输出不匹配对你的意图是什么Razor的假设。<tags>
to determine the transition between code and markup. You can probably use it to generate any text but you might run into issues when your output doesn't match Razor's assumptions about what your intentions are.因此,举例来说,虽然这是有效的剃刀code(因为&LT; DIV&GT;
标记):
So for example while this is valid Razor code (because of the <div>
tag):
@if(printHello) {
<div>Hello!</div>
}
下面的代码片断是无效的(因为你好仍然被视为code!):
The following snippet is invalid (because the Hello! is still being treated as code):
@if(printHello) {
Hello!
}
但是有一个特殊的&LT;文本&GT;
标签可以用来强制多行块(一过渡&LT;文本&GT;
标签将不会被渲染):
However there's a special <text>
tag that can be used to force a transition for multi-line blocks (the <text>
tag will not be rendered):
@if(printHello) {
<text>Hello!
Another line</text>
}
还有一个更短的语法来强制单行使用过渡 @
:
@if(printHello) {
@:Hello!
}