首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >对初级程序员使用Razor的帮助

对初级程序员使用Razor的帮助
EN

Stack Overflow用户
提问于 2011-05-06 15:23:55
回答 2查看 1.6K关注 0票数 1

您好,我有以下示例剃刀script>,现在我需要扩展它,并在@foreach (Dnn.ReportResults().Rows中的DataRow行)后面添加一个if语句,并使用一个if语句检查querystytring值foo是否与名为foo的列的值相同如果这是正确的,则可以呈现该行

代码语言:javascript
运行
复制
<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>

谢谢你的帮助

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-05-06 16:01:03

代码语言:javascript
运行
复制
<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通常是非常有帮助的,特别是对于太多@这样的东西

票数 3
EN

Stack Overflow用户

发布于 2011-05-06 21:26:55

代码语言:javascript
运行
复制
    <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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5908095

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档