From the course: Blazor WebAssembly: Building Your First App

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Code blocks

Code blocks

- [Instructor] A code block is an important part of a Razor component. It allows you to embed C# code into your component. Using the code block, you can declare variables, classes and methods. It also allows you to override the functionality when a component is initialized. This is important so we can control how the UI looks when it's first loaded and what data should be displayed. A Razor component inherits from this component based abstract class. This has a number of methods that help a Razor component function. Anything marked with a virtual keyword indicates that we can override the method inside the Razor component. We will be looking at an OnInitialized and OnInitializedAsync methods. Looking at the component lifecycle, The OnInitialized is called first. If you have methods that are asynchronous and you need to await them, you can use the OnInitializedAsync method. Both of these methods are called once…

Contents