Logo
Logo
  • Blazor CMS Home
  • Oqtane Tutorials
  • Blazor CMS Home
  • Oqtane Tutorials
Oqtane Tutorials
Oqtane Tutorials

Razor Basics Tutorials

Tutorial Home › Razor Basics
Razor Conditions such as if, if-else and ? :
#3 Loops - for and foreach
Work with HTML Output
Resources
  • C# For, ForEach iterations
  • Razor intro
  • Razor Syntax

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>

 

Razor Conditions such as if, if-else and ? :
#3 Loops - for and foreach
Work with HTML Output
  • 2sic internet solutions
  • Langäulistrasse 62, 9470 Buchs SG, Switzerland
  • +41 81 750 67 77
Login