Sign in to track progress and bookmarks.
Razor is the templating engine that mixes HTML with C#. Understanding its nuances is key to building performant UIs.
- @page: Defines the URL route for the component.
- @inject: Injects a service from the DI container.
- @using: Imports namespaces.
- @implements: Specifies an interface implementation (like IDisposable).
For small components, using <code>...</code> blocks inside the .razor file is fine. For large, complex components, use the **Partial Class** pattern. Create a MyComponent.razor.cs file. This keeps your HTML separate from your logic and makes the code much easier to manage and test.
Q: "Should I use @bind or @onchange?"
Architect Answer: "Use @bind for simple two-way data binding. Use @onchange when you need to perform logic (like validation or an API call) immediately after the user changes a value. Remember: @bind is just syntactic sugar for a property and an event—don't be afraid to write it out manually if you need more control."
Quizzes linked to this course—pass to earn certificates.
On this page
1. Directives 2. Code-Behind Pattern 3. Architect Insight