2014-03-25 49 views
1

我想隐藏一个按钮,并显示文本如果没有结果返回我的表中。隐藏一个按钮,如果表空白和显示文字

下面的代码,如果我有我的表:

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

回答

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> 
} 
+0

感谢这工作。我不得不改变'Model.Count',但它是这样读的:@if(Model.Count()> 0)。它曾经是完美的。 – murday1983