开发者

Help with Razor for a beginning programmer

开发者 https://www.devze.com 2023-03-04 14:06 出处:网络
Hi I have the following sample razor script> now I need to extend this and add an if statement after the @foreach (DataRow row in Dnn.ReportResults().Rows) with an if statement to chec开发者_如何学Gok

Hi I have the following sample razor script> now I need to extend this and add an if statement after the @foreach (DataRow row in Dnn.ReportResults().Rows) with an if statement to chec开发者_如何学Gok if the querystytring value foo is the same as the value of the column with name foo if this is correct that tne row can be rendered

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

thanks for the help


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

I've found that if you've got a razor syntax error the YSD that is produced is usually very helpful, especially for things like too many @s


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

0

精彩评论

暂无评论...
验证码 换一张
取 消