如果表格空白并显示文本,则隐藏按钮

时间:2014-03-25 11:13:21

标签: javascript jquery asp.net-mvc html5 asp.net-mvc-5

如果我的表格中没有返回任何结果,我试图隐藏一个按钮并显示文本。

以下代码,如果我的桌子有什么:

<table class="stripped" id="table">
<tr>
    <th>DB ID</th>
    <th>
        @Html.ActionLink("Environment", "Index", new { sortOrder = ViewBag.EnviroSortParam })
    </th>
    <th>
        @Html.ActionLink("Product", "Index", new { sortOrder = ViewBag.ProductSortParam })
    </th>
    <th>
        @Html.ActionLink("Test Type", "Index", new { sortOrder = ViewBag.TestTypeSortParam })
    </th>
    <th>
        @Html.ActionLink("Scenario", "Index", new { sortOrder = ViewBag.ScenarioSortParam })
    </th>
    <th>
        @Html.ActionLink("Times Run", "Index", new { sortOrder = ViewBag.TimesRunSortParam })
    </th>
    <th>
        @Html.ActionLink("Failed Count", "Index", new { sortOrder = ViewBag.FailedCountSortParam })
    </th>
    <th>
        @Html.ActionLink("Last 'Passed' Date", "Index", new { sortOrder = ViewBag.LastPassedDateParam })
    </th>
    <th>
        @Html.ActionLink("Last 'Failed' Date", "Index", new { sortOrder = ViewBag.LastFailedDateParam })
    </th>
    <th>
        Actions
    </th>
</tr>

@foreach (var item in Model)
{
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Id)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Environment)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Product)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.TestType)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Scenario)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.TimesRun)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.FailedCount)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.LastPassedDate)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.LastFailedDate)
        </td>
        <td class="Link">
            @if (item.LastFailedDate != null)
            {
                if (Convert.ToDateTime(item.LastFailedDate).Date == DateTime.Now.Date)
                {
                   @Html.ActionLink("Show Details", "Details", new { id = item.Id })
                    <i class="fa fa-chevron-right"></i>
                }
            }
        </td>
    </tr>
}

下面的代码显示了我的导出按钮的代码:

<div class="RightAlign">
    <button class="butstyle" id="Export" onclick="Export_Click" title="Click to export the results above as a CSV file.">
        Export To Excel <i class="fa fa-table"></i>
    </button>
</div>

正如我所说,如果没有找到结果,我希望隐藏按钮,并显示以下内容:

<p id="NRF" class="NRF">No Test Runs Found.</p>

我怎么能这样做或者最好的方式是什么,因为我似乎无法理解它。我正在使用HTML5&amp; MVC5。

1 个答案:

答案 0 :(得分:4)

@if(Model.Count>0)
{

<div class="RightAlign">
    <button class="butstyle" id="Export" onclick="Export_Click" title="Click to export the results above as a CSV file.">
        Export To Excel <i class="fa fa-table"></i>
    </button>
</div>
}

else
{
<p id="NRF" class="NRF">No Test Runs Found.</p>
}