Razor 不是一种编程语言。它是服务器端的标记语言。编程逻辑:根据条件执行代码。
If 条件
VB 允许根据条件执行代码。
使用 if 语句来判断条件。根据判断结果,if 语句返回 true 或者 false:
- if 语句开始一个代码块
- 条件写在 if 和 then 之间
- 如果条件为真,if ... then 和 end if 之间的代码被执行
实例
@Code Dim price=50 End Code @If price>30 Then @The price is too high.
End If
Else 条件
if 语句可以包含 else 条件。
else 条件定义了当条件为假时被执行的代码。
实例
@Code Dim price=20 End Code @if price>30 then @The price is too high.
Else @The price is OK.
End If
注释:在上面的实例中,如果第一个条件为真,if 块的代码将会被执行。else 条件覆盖了除 if 条件之外的"其他所有情况"。
ElseIf 条件
多个条件判断可以使用 elseif 条件:
实例
@Code Dim price=25 End Code @If price>=30 Then @The price is high.
ElseIf price>20 And price关注打赏