ASP.NET Razor
来源:互联网 发布:vue.js开发app实例 编辑:程序博客网 时间:2024/05/20 11:21
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>
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 条件定义了当条件为假时被执行的代码。
实例
@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>
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>
注释:在上面的实例中,如果第一个条件为真,if 块的代码将会被执行。else 条件覆盖了除 if 条件之外的"其他所有情况"。
ElseIf 条件
多个条件判断可以使用 elseif 条件:
实例
@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>
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>
在上面的实例中,如果第一个条件为真,if 块的代码将会被执行。
如果第一个条件不为真且第二个条件为真,elseif 块的代码将会被执行。
elseif 条件的数量不受限制。
如果 if 和 elseif 条件都不为真,最后的 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>
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 Else),当所有的指定的情况都不匹配时,它覆盖了"其他所有情况"。
阅读全文
0 0
- Asp.Net MVC Razor
- ASP.NET Razor语法
- ASP.NET Razor - C#
- ASP.NET Razor - 标记
- ASP.NET Razor - 标记
- ASP.NET Razor
- ASP.NET Razor
- ASP.NET Razor
- ASP.NET Razor
- ASP.NET Razor
- ASP.NET Razor
- ASP.NET Razor
- ASP.NET Razor
- ASP.NET Razor
- ASP.NET Razor
- ASP.NET MVC3 Razor 语法
- ASP.NET MVC3 Razor布局
- Asp.net MVC3 Razor语法
- ASP.NET Razor
- 一个程序员要扔掉多少代码,才能成为真正的程序员
- 不用加减乘除做加法
- 自定义ListView
- mac vim 默认显示行号
- ASP.NET Razor
- Jeesite添加自定义tld标签的方式
- Less的@import指令
- ASP.NET MVC 教程
- 入门 node.js 你必须知道的那些事
- 介绍Spring Cloud构建微服务架构
- ASP.NET MVC
- js获取jstl域中的值
- 深入理解Java内存模型(七)——总结