Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
How to perform common logical tasks in Razor like if/else, foreach loops, switch statements and using the @ character to separate code and markup
Shows how to perform common logical tasks in Razor like if/else, foreach loops, switch statements and using the @ character to separate code and markup.
The @ symbol is used in Razor to initiate code, and tell the compiler where to start interpreting code, instead of returning the content of the file as text. Using a single character for this separation, results in cleaner, compact code which is easier to read.
Commenting your code is important, use comments to explain what the code does. @* *@
indicates a comment, which will not be visible in the rendered output.
If/else statements perform one task if a condition is true, and another if the condition is not true
A foreach loop goes through a collection of items, typically a collection of pages and performs an action for each item
A Switch block is used when testing a large number of conditions