Razor 我们什么时候使用@&引用;剃刀

Razor 我们什么时候使用@&引用;剃刀,razor,Razor,我正在读这样一本书中的一个例子: @switch ((int)ViewBag.ProductCount) {                 case 0:                     @: Out of Stock                     break;                 case 1:                     <b>Low Stock (@ViewBag.ProductCount)</b>            

我正在读这样一本书中的一个例子:

@switch ((int)ViewBag.ProductCount) {
                case 0:
                    @: Out of Stock
                    break;
                case 1:
                    <b>Low Stock (@ViewBag.ProductCount)</b>
                    break;
                default:
                    @ViewBag.ProductCount
                    break;
            }
@开关((int)ViewBag.ProductCount){
案例0:
@:缺货
中断;
案例1:
低库存(@ViewBag.ProductCount)
中断;
默认值:
@ViewBag.ProductCount
中断;
            }

所以我的问题是,我们如何确定何时何地需要“@”?例如
ViewBag.ProductCount
没有,但在
案例1中:
它有。

在代码块开始之前需要@符号:

@{
    // code here
 }
或出现在mHTML标记中的流控制语句之前@

@if(this || that){
    <h1>Hello World</h1>
}
else
{
    <h1>Good bye</h1>
}

你可以在我的网站上阅读更多内容:

试试这个@DavidG就可以了,同时你也可以试试这个:我以为我会在那里玩得很开心:)
@Datetime.Now // will render the current time to the browser 
@(2/2 == 1) // will render 'true' to the browser