以下是我的观看页面
<table class="travTableCont width_full" cellspacing="0" cellpadding="0" border="0">
@if(Model.lstunutilizedownershipentities.Count==0)
{
<script type="text/javascript">
$(document).ready(function () {
$("#header").hide();
});
</script>
<tr style="text-align:center;">
<label>No data is Available</label>
</tr>
}
<thead id="header">
<tr>
<th style="width: 50%;">
@Model.lstCommonLabels.lblCurrentOwnership
</th>
<th>
@Model.lstCommonLabels.lblCount
</th>
</tr>
</thead>
<tfoot>
</tfoot>
</table>
<div id="pagecontent" style=" overflow:auto;height:300px;">
<table class="travTableCont width_full" border="0" cellspacing="0" cellpadding="0">
<tbody class="travTableContent">
@foreach (var item in Model.lstunutilizedownershipentities)
{
<tr>
<td class="tdo" style="width: 30%;">@item.CurrentOwnership</td>
<td class="tdt"><a href="#" onclick="javascript:GetDetail('@item.CurrentOwnership');">@item.cnt</a></td>
</tr>
}
</tbody>
</table>
</div>
在上面的代码中我给出了if条件,@if(Model.lstunutilizedownershipentities.Count==0)
它在lstunutilizedownershipentities.Count==0
以及lstunutilizedownershipentities.Count!=0
时有效。我想在lstunutilizedownershipentities.Count!=0
时显示表头。
答案 0 :(得分:0)
如果您认为此代码块始终运行,则必须断言。最简单的方法是:
<p>@Model.lstunutilizedownershipentities.Count</p>
ready()
为0且不是Model.lstunutilizedownershipentities.Count
代码块
如果您确认这一点,就会发现Razor引擎存在错误。否则,您可能会在更新视图模型的地方附近出现错误。
答案 1 :(得分:0)
您的HTML中可能有另一个元素id="header"
(可能在布局文件中)。
试试这个:
...
$("#header2").hide();
...
...
<thead id="header2">
...
...
如果我的解决方案不起作用,请尝试检查#header
元素的CSS。也许,有display: none !important;
答案 2 :(得分:0)
@model <-- this is your model
<table>
<tr style="text-align:center;">
<label>No data is Available</label>
</tr>
}
@{
if (Model.lstunutilizedownershipentities.Count ==0)
{
<thead id="header">
<tr>
<th style="width: 50%;">
@Model.lstCommonLabels.lblCurrentOwnership
</th>
<th>
@Model.lstCommonLabels.lblCount
</th>
</tr>
</thead>
}
}
<tbody>
</tbody>
</table>
@foreach(Model.lstunutilizedownershipentities中的var项)
{
@ item.CurrentOwnership
@ item.cnt
}