1

我使用 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>
}

另外,请随时纠正我对行话的不当使用。

4

2 回答 2

3

除了<text>标签,您还可以在您的行前加上@:

@if (Model.IsAlreadyConfirmed)
{
     @:This account has already been confirmed.
}
于 2013-08-12T19:05:56.737 回答
1
@if (Model.IsAlreadyConfirmed)
{
     <text>This account has already been confirmed.</text>
}

有一个名为 text 的特殊标签,它只会打印出您放入其中的内容。在呈现的 html 中省略了实际的标签。

于 2013-08-12T18:56:23.967 回答