@{
int counter = 1;
foreach (var item in Model.Stuff) {
... some code ...
counter = counter + 1;
}
}
Explanation:
@{
// csharp code block
// everything in here is code, don't have to use @
int counter = 1;
}
@foreach(var item in collection){
<div> - **EDIT** - html tag is necessary for razor to stop parsing c#
razor automaticaly recognize this as html <br/>
this is rendered for each element in collection <br/>
value of property: @item.Property <br/>
value of counter: @counter++
</div>
}
this is outside foreach