我有以下片段:
<ul>
@foreach (var product in Model.Products)
{
<li>@product.Name x@product.Count</li>
}
</ul>
它将 x@product.Count 视为文字。如何在 @ 符号之前放置一个字符?
最佳答案
该场景允许 foo@your.com
(电子邮件)不受干扰地存在于现有标记中。相反,使用:
x@(product.Count)
(紧跟在@
之后的额外括号,即@(...)
表示显式代码表达式)
或更好的 html-wise:
×@(product.Count)
您可能还会发现这很方便:
×@product.Count
关于c# - 为什么 Razor 没有将其检测为 ASP.NET MVC 中的代码块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7143532/