ASP.NET Razor - VB 逻辑条件
If 条件
VB 代码。
可以使用 if 语句。if 返回 true 或 false:
- if 码块
- 条件位于 if 和 then 之间
- if ... then 与 end if
实例
@Code
Dim price=50
End Code
<html>
<body>
@If price>30 Then
@<p>The price is too high.</p>
End If
</body>
</html>
运行实例
Else 条件
if 含 else 条件。
else 件为 false 码。
实例
@Code
Dim price=20
End Code
<html>
<body>
@if price>30 then
@<p>The price is too high.</p>
Else
@<p>The price is OK.</p>
End If
</body>
</htmlV>
运行实例
注释: 30
ElseIf 条件
可通过 else if 条件条件:
实例
@Code
Dim price=25
End Code
<html>
<body>
@If price>=30 Then
@<p>The price is high.</p>
ElseIf price>20 And price<30
@<p>The price is OK.</p>
Else
@<p>The price is low.</p>
End If
</body>
</html>
运行实例
为 true。
为 true。
else if 条件。
如果 if 和 else if true后一个 else 代码块。
Select 条件
select 代码块的条件:
实例
@Code
Dim weekday=DateTime.Now.DayOfWeek
Dim day=weekday.ToString()
Dim message=""
End Code
<html>
<body>
@Select Case day
Case "Monday"
message="This is the first weekday."
Case "Thursday"
message="Only one day before weekend."
Case "Friday"
message="Tomorrow is weekend!"
Case Else
message="Today is " & day
End Select
<p>@message</p>
</body>
</html>
运行实例
"Select Case" 值 (day)以 case 配 case 代码行。
select case (default:)有 case 均不为 true 。