2011-05-06 28 views
1

嗨我有以下示例剃鬚刀腳本>現在我需要擴展此並添加if語句後@foreach(DataRow行在Dnn.ReportResults()。行)與if語句檢查是否querystytring值foo是同一個名爲foo列的值,如果這是正確的,TNE行可以呈現幫助一個開始程序員的剃刀

<table> 
<thead> 
@{var table = Dnn.ReportResults();} 
<tr> 
@foreach (DataColumn col in table.Columns) 
{ 
<th>@col.ColumnName</th> 
} 
</tr> 
</thead> 
<tbody> 
@foreach (DataRow row in Dnn.ReportResults().Rows) 
{ 
<tr> 
@foreach (var value in row.ItemArray) 
{ 
<td>@value</td> 
} 
</tr> 
} 
</tbody> 
</table> 

感謝您的幫助

+0

各種嘗試用如果的Request.QueryString [ 「富」]我coudl得到它在普通的C#asp.net應用工作。我想我只需要在剃鬚刀設置中看到它,我一定錯過了}或@ – nokiko 2011-05-06 07:35:06

回答

3
<tbody> 
@foreach (DataRow row in Dnn.ReportResults().Rows) 
{ 
    if(Request.QueryString["foo"] == "bar") 
    { 
     <tr> 
     @foreach (var value in row.ItemArray) 
     { 
      <td>@value</td> 
     } 
     </tr> 
    } 
} 
</tbody> 

我已經發現如果你的剃刀語法錯誤,產生的YSD通常是非常有用的,特別是espe cially喜歡的事情太多@s

0
<table> 
    <thead> 
    @{var table = Dnn.ReportResults();} 
<tr> 
    @foreach (DataColumn col in table.Columns) 
    { <th>@col.ColumnName 
     </th> } 
</tr> 
</thead> 
<tbody> 
    @foreach (DataColumn col in table.columns) 
    { 
     if (col.ColumnNamn == Request.QueryString["foo"]) 
     { 
    foreach (DataRow row in Dnn.ReportResults().Rows) 
    { <tr> 
     @foreach (var value in row.ItemArray) 
     { <td>@value 
      </td> 
     } 
    </tr> 
    } 
     } 
    } 
</tbody>