2011-05-06 48 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>