@{ int i = 0;}
@foreach (var providerInfo in Model.Results)
{
<div class="row">
i = i + 1;
Inside the for-each loop I want to have a counter so I tried yo define my variable outside of it as above but Razor doesn't get it! What is the correct Syntax to do this?
In your case statement i = i + 1;
is currently interpreted as part of HTML. In order to tell Razor to interpret it as C# code, you can wrap your increment code with a @{ }
:
@{ int i = 0;}
@foreach (var providerInfo in Model.Results)
{
<div class="row">
@{i = i + 1; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With