0

我在视图中有一个标准列表。每行都有一个 actionlink 调用 ViewSubalert。但并非每条记录都有子警报或子警报,因此我想隐藏没有基础值的操作链接。

查看子警报 一个警报 另一个警报 查看子警报 另一个警报

这在使用 Web 表单的 Gridview 中非常容易,但不确定如何在 MVC 4 中执行此操作。操作链接 snytax:

 @Html.ActionLink("View Sub Alerts", "Index","SubAlerts", new { id = item.AlertID }, new { 
 @class = "SubAlertModalOpener" })
4

1 回答 1

0

有条件地渲染它

@if( HasSubAlert == true)
{
    @Html.ActionLink("View Sub Alerts", "Index","SubAlerts", new { id = item.AlertID }, new {  @class = "SubAlertModalOpener @"})
}

或者

(我没有测试过):

您可以添加style = "@( condition ? string.empty : "display:none")"HTML 属性,例如

@Html.ActionLink("View Sub Alerts", "Index","SubAlerts", new { id = item.AlertID }, new {  @class = "SubAlertModalOpener @",  style = @( condition ? string.empty : "display:none")  })
于 2013-08-30T16:50:03.997 回答