Razor syntax
Razor syntax is made up of HTML, Razor markup, and C#. Rendering HTML from a Razor component is the same as rendering HTML from an HTML file. Razor syntax uses both inline expressions and control structures to render dynamic values.
Inline expressions
Inline expressions start with an @
symbol followed by a variable or function name. This is an example of an inline expression:
<h1>Blazor is @Text!</h1>
In the preceding example, Blazor will interpret the text after the @
symbol as either a property name or a method name.
Control structures
Control structures also start with an @
symbol. The content within the curly brackets is evaluated and rendered to the output. This is an example of an if
statement from the FetchData
component in the Demo
project that we will create later in this chapter:
@if (forecasts == null)
{
<p><em>Loading...</em></p>
}
Conditionals
The following types of conditionals...