Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET循环计数器_C#_Asp.net_Asp.net Mvc_Asp.net Mvc 4_Razor - Fatal编程技术网

C# ASP.NET循环计数器

C# ASP.NET循环计数器,c#,asp.net,asp.net-mvc,asp.net-mvc-4,razor,C#,Asp.net,Asp.net Mvc,Asp.net Mvc 4,Razor,我的ASP.NET代码中有一个foreach循环,我试图通过在循环末尾添加@counter++来添加计数器,但它不起作用,我得到一个无效的表达式术语错误。我也试过@{counter++},但也没用 <table border="1" style="width:762px;height:25px; border-style:1px solid #000; border-collapse:collapse; clear:both;"> @{ int counter = 1; }

我的ASP.NET代码中有一个
foreach
循环,我试图通过在循环末尾添加
@counter++
来添加计数器,但它不起作用,我得到一个无效的表达式术语错误。我也试过
@{counter++}
,但也没用

<table border="1" style="width:762px;height:25px; border-style:1px solid #000; border-collapse:collapse; clear:both;">
@{
    int counter = 1;
}
@foreach (var person in @ViewBag.POLoopList)
{
    <tr>
        <td style="width:24px; text-align:right;">@counter</td>
        <td style="width:55px">@person.EstPhase</td>
        <td style="width:32px">@person.JCCategory</td>
        <td style="width:180px">@person.ItemsDesc</td>
        <td style="width:90px; text-align:left;">@person.Comments</td>
        <td style="width:57px; text-align:right;">@person.OrderQty</td>
        <td style="width:40px; text-align:center;">@person.OrderUOM</td>
        <td style="width:56px; text-align:right;">@Convert.ToDouble(person.Rate).ToString("N")</td>
        <td style="width:70px; text-align:right;">$@Convert.ToDouble(person.Pretax).ToString("N")</td>
    </tr>
    @counter++
}
</table>

@{
int计数器=1;
}
@foreach(var person in@ViewBag.POLoopList)
{
@柜台
@人名阶段
@person.jc类别
@person.ItemsDesc
@个人意见
@个人订单数量
@person.OrderUOM
@将.ToDouble(person.Rate).ToString(“N”)
$@Convert.ToDouble(person.Pretax.ToString(“N”)
@柜台++
}

@计数器+
中删除
@

<table border="1" style="width:762px;height:25px; border-style:1px solid #000; border-collapse:collapse; clear:both;">
            @{
                int counter = 1;
            }
            @foreach (var person in @ViewBag.POLoopList)
            {
                <tr>
                    <td style="width:24px; text-align:right;">@counter</td>
                    <td style="width:55px">@person.EstPhase</td>
                    <td style="width:32px">@person.JCCategory</td>
                    <td style="width:180px">@person.ItemsDesc</td>
                    <td style="width:90px; text-align:left;">@person.Comments</td>
                    <td style="width:57px; text-align:right;">@person.OrderQty</td>
                    <td style="width:40px; text-align:center;">@person.OrderUOM</td>
                    <td style="width:56px; text-align:right;">@Convert.ToDouble(person.Rate).ToString("N")</td>
                    <td style="width:70px; text-align:right;">$@Convert.ToDouble(person.Pretax).ToString("N")</td>
                </tr>
            counter++
            }
        </table>

@{
int计数器=1;
}
@foreach(var person in@ViewBag.POLoopList)
{
@柜台
@人名阶段
@person.jc类别
@person.ItemsDesc
@个人意见
@个人订单数量
@person.OrderUOM
@将.ToDouble(person.Rate).ToString(“N”)
$@Convert.ToDouble(person.Pretax.ToString(“N”)
柜台++
}

@计数器+
中删除
@

<table border="1" style="width:762px;height:25px; border-style:1px solid #000; border-collapse:collapse; clear:both;">
            @{
                int counter = 1;
            }
            @foreach (var person in @ViewBag.POLoopList)
            {
                <tr>
                    <td style="width:24px; text-align:right;">@counter</td>
                    <td style="width:55px">@person.EstPhase</td>
                    <td style="width:32px">@person.JCCategory</td>
                    <td style="width:180px">@person.ItemsDesc</td>
                    <td style="width:90px; text-align:left;">@person.Comments</td>
                    <td style="width:57px; text-align:right;">@person.OrderQty</td>
                    <td style="width:40px; text-align:center;">@person.OrderUOM</td>
                    <td style="width:56px; text-align:right;">@Convert.ToDouble(person.Rate).ToString("N")</td>
                    <td style="width:70px; text-align:right;">$@Convert.ToDouble(person.Pretax).ToString("N")</td>
                </tr>
            counter++
            }
        </table>

@{
int计数器=1;
}
@foreach(var person in@ViewBag.POLoopList)
{
@柜台
@人名阶段
@person.jc类别
@person.ItemsDesc
@个人意见
@个人订单数量
@person.OrderUOM
@将.ToDouble(person.Rate).ToString(“N”)
$@Convert.ToDouble(person.Pretax.ToString(“N”)
柜台++
}

如果在foreach中,并且没有将变量放置在html元素中,则不需要@符号

更改:

@counter++


此外,这里有一个关于

的快速指南,当您在foreach中并且没有将变量放置在html元素中时,您不需要@符号

更改:

@counter++

此外,这里是一个很好的快速指南