帮助剃刀编程新手剃刀、新手

2023-09-06 22:08:55 作者:青春用来挥霍

您好我有以下示例剃须刀SCRIPT>现在我需要延长这一点,如果添加了@foreach后声明(DataRow的行Dnn.ReportResults()。行)与if语句来检查querystytring值FOO是一样的名为foo的列的值,如果这是正确的TNE行可以呈现

 <表>
< THEAD>
@ {VAR表= Dnn.ReportResults();}
&其中; TR>
 @foreach(COL的DataColumn在table.Columns)
 {
 <第i个@ col.ColumnName< /第i个
 }
< / TR>
< / THEAD>
< TBODY>
 @foreach(DataRow的行Dnn.ReportResults()。行)
 {
 &其中; TR>
 @foreach(在row.ItemArray VAR值)
 {
 < TD> @值小于; / TD>
 }
< / TR>
}
< / TBODY>
< /表>
 

感谢您的帮助

解决方案

 < TBODY>
 @foreach(DataRow的行Dnn.ReportResults()。行)
 {
    如果(的Request.QueryString [富] ==巴)
    {
        &其中; TR>
        @foreach(在row.ItemArray VAR值)
        {
            < TD> @值小于; / TD>
        }
        < / TR>
    }
}
< / TBODY>
 

我发现,如果你已经有了一个剃刀语法错误时产生的YSD通常是非常有帮助的,特别是对于像太多@s

2017年IT行业依然是高薪的热点

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

 
精彩推荐
图片推荐