【问题标题】:Hide a button if table blank and display text如果表格空白并显示文本,则隐藏按钮
【发布时间】:2014-05-03 04:39:28
【问题描述】:

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

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

<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 和 MVC5。

【问题讨论】:

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


    【解决方案1】:
    @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>
    }
    

    【讨论】:

    • 感谢这项工作。我不得不更改'Model.Count',所以它显示为:@if(Model.Count() > 0)。一旦这样做,它就完美了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-24
    • 2020-11-06
    • 2014-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-26
    相关资源
    最近更新 更多