加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 使用Razor和.NET的一行If语句

发布时间:2020-12-16 07:17:41 所属栏目:asp.Net 来源:网络整理
导读:Razor似乎不喜欢我的一行If语句…通常在VB.NET中,我可以写一行if语句如下: If True Then Dim x As Integer 但是,当我在像这样的.vbhtml文件中使用Razor时… @If True Then Dim x As Integer 我收到了错误 The “If” block was not terminated. All “If”
Razor似乎不喜欢我的一行If语句…通常在VB.NET中,我可以写一行if语句如下:

If True Then Dim x As Integer

但是,当我在像这样的.vbhtml文件中使用Razor时…

@If True Then Dim x As Integer

我收到了错误

The “If” block was not terminated. All “If” statements must be terminated with a matching “End If”.

是什么赋予了? Razor为什么不接受这个?我意识到一个简单的解决方案就是使用类似的代码块

@code
    If True Then Dim x As Integer
End Code

但那不是我想要的.我很好奇为什么Razor无法识别VB.Net的一行if语句只使用@If ….任何想法?

解决方法

与C#相同的问题,如 here所述:

Razor uses code syntax to infer indent: Razor Parser infers code
ending by reading the opening and the closing characters or HTML
elements. In consequence,the use of openings “{“ and closings “}” is
mandatory,even for single line instructions

你做的是怀特的事

@code
    If True Then Dim x As Integer
End Code

你可以这样做,但不是你喜欢的(内联)

@If (True) Then
    Dim x As Integer
End If

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读