Asp.net mvc MVC Razor VB.NET中的条件高亮显示行
我想根据条件是否为真来更改行的背景色。我尝试了以下方法,但它不喜欢语法。我尝试过几种不同的方法,但它不喜欢其中任何一种Asp.net mvc MVC Razor VB.NET中的条件高亮显示行,asp.net-mvc,vb.net,razor,Asp.net Mvc,Vb.net,Razor,我想根据条件是否为真来更改行的背景色。我尝试了以下方法,但它不喜欢语法。我尝试过几种不同的方法,但它不喜欢其中任何一种 @<tr class="@if (item.ActualDeliveries <> item.ExpectedDeliveries ) then string.empty else "style=background-color:Yellow" End if)"> @
@<tr class="@if (item.ActualDeliveries <> item.ExpectedDeliveries )
then string.empty
else "style=background-color:Yellow"
End if)">
@
这是我得到的错误:
“If”块未终止。所有“If”块语句必须以匹配的“End If”终止。
string.empty不是一个方法
else语句中显示“语法错误”
--更新
即使使用以下语句,razor也不会输出任何内容。但是,如果我在“”结束标记后使用“end if”,它就可以工作了
If True Then
@:<tr>
End If
<td>
@Html.DisplayFor(Function(modelItem) currentItem.StartDate)
</td>
<td>
@Html.ActionLink("Edit", "Edit", New With {.id = currentItem.ID})
</td>
</tr>
如果为True,则
@:
如果结束
@DisplayFor(函数(modelItem)currentItem.StartDate)
@ActionLink(“编辑”,“编辑”,新的,带有{.id=currentItem.id})
不要尝试在标记本身内解析Razor,而是尝试以下方法:
@If item.ActualDeliveries <> item.ExpectedDeliveries Then
<tr>
Else
<tr style="background-color:yellow">
End If
@If item.ActualDeliveries item.ExpectedDeliveries然后
其他的
如果结束
您可能会收到来自设计器的警告,但您可以忽略这些警告-将在运行时生成正确的HTML。此外,如果实际编译了标记,则您的标记将创建如下内容:
<tr class="style=background-color:yellow">
这显然是不正确的。试试这个:
<tr class="@(If(item.ActualDeliveries = item.ExpectedDeliveries, "style=background-color:Yellow;", String.Empty))"
Define“不喜欢语法”。您看到了什么错误?未终止“If”块。所有“If”块语句都必须以匹配的“End If”终止。string.empty不是一个方法,然后在else语句中它说“Syntax error”,我尝试了您所说的,但没有。当所需事件发生时,页面上没有输出表。我必须在标签前面使用@:否则它找不到else或end if。还有其他想法吗?