2014-10-10 133 views
0

我試圖在我的視圖中顯示記錄。我只想顯示TABLE_NUMBER1字段沒有空值的記錄。我已經設置好了,但是有一個奇怪的問題,它不會識別else的結束標記,只有foreach和if。具體來說,如果我爲else添加結束標記,它會將它識別爲整個razer部分的結束標記(也就是金子)。cshtml查看裏面的其他foreach

@if (Model.Count() == 0) 
{ 
    <tbody> 
    <tr> 
     <td colspan="7"> 
      No Records match search criteria 
     </td> 
    </tr> 
     </tbody> 
} 
else{   
foreach (var item in Model) 
{ 
    var hiderows = @Html.DisplayFor(modelItem => item.TABLE_NUMBER1).ToString(); 
    if (hiderows != null) 
    {  
     <tbody>  
     <tr> 
      <td> 
      <p class="one">@Html.DisplayFor(modelItem => item.PNTR_MAX)</p> 
     </td> 
      <td> 
      <p class="one">@Html.DisplayFor(modelItem => item.EFFECTIVE_DATE1)</p> 
     </td> 
      <td> 
      <p class="one">@Html.DisplayFor(modelItem => item.BANK_ROUTING_NUMBER)</p> 
     </td> 
      <td> 
      <p class="one">@Html.DisplayFor(modelItem => item.TAX_ID)</p> 
     </td> 
      <td> 
      <p class="one">@Html.DisplayFor(modelItem => item.BANK_NAME)</p> 
     </td> 
      <td> 
      <p class="one">@Html.DisplayFor(modelItem => item.COMPANY_NAME1)</p> 
     </td> 
     <td> 
      @Html.ActionLink("Edit", "..\\Table9\\Edit", new { id = item.EFTID }) 
      @Html.ActionLink("Details", "..\\Table9\\Details", new { id = item.EFTID }) 
      @Html.ActionLink("Delete", "..\\Table9\\Delete", new { id = item.EFTID }) 
     </td>    
    </tr> 
</tbody> 
} 
} 
} 

回答

0

這是錯誤的:

var hiderows = @Html.DisplayFor(modelItem => item.TABLE_NUMBER1); 

將其更改爲:

@Html.DisplayFor(modelItem => item.TABLE_NUMBER1) 
if (item.TABLE_NUMBER1!= null) 
{ 
+0

也做到了,謝謝! – 2014-10-10 18:30:40