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

Razor Basics Tutorials

Tutorial Home › Razor Basics
Quick Reference for all APIs
#1 Basic set variable and show
Razor Conditions such as if, if-else and ? :
Resources
  • Razor intro
  • Razor Syntax
  • C# Arrays
  • C# Variables

Basic set variable and show

var Firstname = "Terry" and show with @firstName

Just a simple variable - create and show.

⬇️ Result | Source ➡️

Name: Terry
@inherits Custom.Hybrid.RazorTyped
@{
  var firstName = "Terry";
}

Name: @firstName

⬇️ Result | Source ➡️

Age: 27
Birthday: 9/9/1999 12:00:00 AM
Birthday nicer using ToString("d"): 9/9/1999
Birthday as ISO ToString("yyyy-MM-dd"): 1999-09-09
@inherits Custom.Hybrid.RazorTyped

@{
  var age = 27;
  var birthday = new DateTime(1999, 09, 09);
}
Age: @age <br>
Birthday: @birthday <br>
Birthday nicer using ToString("d"): @birthday.ToString("d") <br>
Birthday as ISO ToString("yyyy-MM-dd"): @birthday.ToString("yyyy-MM-dd")

⬇️ Result | Source ➡️

Dog Count: 3
Dog[0]: hound
Dog First (with LINQ): hound
Dog Last (with LINQ): doggy
  1. Dog 0: hound
  2. Dog 1: dackel
  3. Dog 2: doggy
@inherits Custom.Hybrid.RazorTyped

@{
  var dogs = new string[] { "hound", "dackel", "doggy" };
}
<div>
  Dog Count: @dogs.Length <br>
  Dog[0]: @dogs[0] <br>
  Dog First (with LINQ): @dogs.First() <br>
  Dog Last (with LINQ): @dogs.Last() <br>
</div>

<ol>
  @for (int i = 0; i < dogs.Length; i++) {
    <li>Dog @i: @dogs[i]</li>
  }
</ol>

 

Quick Reference for all APIs
#1 Basic set variable and show
Razor Conditions such as if, if-else and ? :
  • 2sic internet solutions
  • Langäulistrasse 62, 9470 Buchs SG, Switzerland
  • +41 81 750 67 77
Login