显示/隐藏基于列值的jQuery数据表动作链接按钮



用于检索数据的LINQ查询:

public ActionResult GetRegFirmList()
{
try
{
var data = (from z in db.BusinessModels
select z).OrderByDescending(z => z.BusinessKey).ToList();
return View(data);
}
catch (Exception ex) { throw; }
}

在jQuery数据表中有两个动作链接按钮。如果Status的值是特定行中的1,我需要隐藏Certificate的按钮。Application的动作链接按钮不应该被隐藏。我该怎么做呢?

<link href="~/Content/DataTables/css/dataTables.bootstrap.min.css" rel="stylesheet" />
<table id="tblBusinessData">
<thead class="table-success">
<tr>
<th>generate</th>
<th style="visibility:hidden;">
@Html.DisplayNameFor(model => model.BusinessKey)
</th>
<th>
@Html.DisplayNameFor(model => model.BusinessName)
</th>
<th>
@Html.DisplayNameFor(model => model.PropName)
</th>
<th>
@Html.DisplayNameFor(model => model.Status)
</th>

</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.ActionLink("Certificate", "GenerateCertificate", new { id = item.BusinessKey }, new { @class = "btn btn-warning" })
@Html.ActionLink("Application", "GenerateApplication", new { id = item.BusinessKey }, new { @class = "btn btn-warning" })
</td>
<td style="visibility:hidden;">
@Html.DisplayFor(modelItem => item.BusinessKey)
</td>
<td>
@Html.DisplayFor(modelItem => item.BusinessName)
</td>
<td>
@Html.DisplayFor(modelItem => item.PropName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Status)
</td>
</tr>
}
</tbody>
</table>
<script src="~/Scripts/DataTables/jquery.dataTables.min.js"></script>
<script src="~/Scripts/DataTables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript">
$('#tblBusinessData').DataTable({
"columnDefs": [{
"targets": [1],
"visible": false
}],
"order": [
[1, "desc"]
]
});
</script>

您可以添加这样的条件

@if(item.Status!=1)  
{
@Html.ActionLink("Certificate", "GenerateCertificate", new { id = item.BusinessKey }, new { @class = "btn btn-warning" })
}
所以你的foreach循环应该在 下面
@foreach (var item in Model)
{
<tr>
<td>
@(item.Status!=1){@Html.ActionLink("Certificate", "GenerateCertificate", new { id = item.BusinessKey }, new { @class = "btn btn-warning" })}
@Html.ActionLink("Application", "GenerateApplication", new { id = item.BusinessKey }, new { @class = "btn btn-warning" })
</td>
<td style="visibility:hidden;">
@Html.DisplayFor(modelItem => item.BusinessKey)
</td>
<td>
@Html.DisplayFor(modelItem => item.BusinessName)
</td>
<td>
@Html.DisplayFor(modelItem => item.PropName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Status)
</td>
</tr>
}

最新更新