App


Razor Basics Tutorials

Tutorial HomeRazor Basics

Loops - for and foreach

⬇️ Result | Source ➡️

  • dog
  • cat
  • mouse
@inherits Custom.Hybrid.RazorTyped

@{
  var pets = new string[] { "dog", "cat", "mouse"};
}

<ul>
  @foreach (var pet in pets) {
    <li>@pet</li>
  }
</ul>

⬇️ Result | Source ➡️

  • dog
  • cat
  • mouse
@inherits Custom.Hybrid.RazorTyped

@{
  var pets = new string[] { "dog", "cat", "mouse"};
}

<ul>
    @for(var i = 0; i < pets.Length; i++) {
      <li>@pets[i]</li>
    }
</ul>

⬇️ Result | Source ➡️

  • dog - owned by Daniel
  • cat - owned by John
  • mouse - owned by Markus
@inherits Custom.Hybrid.RazorTyped

@{
  var pets = new string[] { "dog", "cat", "mouse"};
  var owners = new string[] { "Daniel", "John", "Markus"};
}

<ul>
    @for(var i = 0; i < pets.Length; i++) {
      <li>@pets[i] - owned by @owners[i]</li>
    }
</ul>