'In this For loop count is not increasing

            <tbody>
                @foreach (var item in Model)
                {
                    int count = 1;
                    <tr>
                        <td>@count</td>
                        <td>@item.ProductName</td>
                        <td>

                            @Html.ActionLink("Edit", "ProductEdit", new { productId = item.ProductId })
                        </td>

                    </tr>
                    count = count + 1;
                }

            </tbody>

This code is to display the products in a table with serial number as count but the count is not increasing



Solution 1:[1]

Because you are reassigning it to 1 for every iteration , initialize it before the loop starts

Solution 2:[2]

you need to set the count value before the foreach iterates over the data, otherwise the count value will not increasee

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Arsalan Khan
Solution 2 Housheng-MSFT