我使用Razor非常遵循这种模式:
@if (Model.IsAlreadyConfirmed)
{
This account has already been confirmed.
}
但这不起作用,因为它期待代码。我被迫做这样的事情:
@if (Model.IsAlreadyConfirmed)
{
@Html.Raw("This account has already been confirmed.")
}
或者这个:
@if (Model.IsAlreadyConfirmed)
{
<span>This account has already been confirmed.</span>
}
另外,请随意纠正我不当使用行话。
答案 0 :(得分:3)
除<text>
标记外,您还可以使用@:
@if (Model.IsAlreadyConfirmed)
{
@:This account has already been confirmed.
}
答案 1 :(得分:1)
@if (Model.IsAlreadyConfirmed)
{
<text>This account has already been confirmed.</text>
}
有一个名为text的特殊标签,只打印出你放入的内容。渲染的html中省略了实际标记。