首页 > 其他 > 详细

怎对于Foreach 不能添加IF的问题

时间:2014-05-31 05:10:39      阅读:402      评论:0      收藏:0      [点我收藏+]

我不们直接在Foreach 里面直接添加IF,这样会报错,这个前提是子视图,其他的我没有试验过。像这样:

1
2
3
4
5
6
7
8
9
10
11
@foreach (Gift.Modules.Model.Entitys.XT_CZ item in ViewData["ZTCZ"] as IList<Gift.Modules.Model.Entitys.XT_CZ>)
{
    string htmlfaction = @item.Action + "()";
    if (true)
    {
         @saveorcancel = true;
    }
    <a href="javascript:void(0)" id="@item.Action" onclick="@htmlfaction" class="easyui-linkbutton" data-options="iconCls:‘@item.IconCls‘" style="width: 80px; margin-right: 5px; margin: 5px;">
        @item.CZMC
    </a>
}

 应该改成这样:

1
2
3
4
5
6
7
8
9
10
11
12
13
@foreach (Gift.Modules.Model.Entitys.XT_CZ item in ViewData["ZTCZ"] as IList<Gift.Modules.Model.Entitys.XT_CZ>)
{
    string htmlfaction = @item.Action + "()";
    <text>
    @if (true)
    {
         saveorcancel = true;
    }
    </text>
    <a href="javascript:void(0)" id="@item.Action" onclick="@htmlfaction" class="easyui-linkbutton" data-options="iconCls:‘@item.IconCls‘" style="width: 80px; margin-right: 5px; margin: 5px;">
        @item.CZMC
    </a>
}

 这样就可以正常运行。

怎对于Foreach 不能添加IF的问题,布布扣,bubuko.com

怎对于Foreach 不能添加IF的问题

原文:http://www.cnblogs.com/armyant/p/3761631.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!