User Interaction in Blazor

User Interaction is the third chapter of the free Blazor tutorial. It shows how a Blazor app listens to the user: forms, inputs and events.

What each lesson covers:

  • Forms & Events: Input components and data binding, one-way and two-way binding, click, mouse, keyboard, focus and change events, EditForm and models, custom inputs, OnSubmit and form reset.
  • Form Validation: Data annotations and validation attributes, custom error messages, ValidationSummary and ValidationMessage, styling, OnValidSubmit and OnInvalidSubmit, custom and cross-field rules, and clearing messages.

Every code box compiles your components with the real Razor compiler and runs them on .NET 10 in your browser.

Lessons in this section

  1. Forms & Events

    Forms and events in Blazor: input components with @bind-Value, one-way and two-way binding, click, mouse, keyboard, focus and change events, EditForm and models, custom inputs, OnSubmit and resetting a form.

    • Bind input components to a model with @bind-Value
    • Tell one-way binding from two-way binding
    • Handle click, mouse, keyboard, focus and change events
    • Build an EditForm, submit it with OnSubmit and reset it
  2. Form Validation

    Form validation in Blazor: DataAnnotationsValidator, validation attributes and custom error messages, ValidationSummary and ValidationMessage, styling messages, OnValidSubmit and OnInvalidSubmit, custom attributes, cross-field rules and clearing messages.

    • Add rules to a model with data annotation attributes
    • Show errors with ValidationSummary and ValidationMessage
    • Save only correct forms with OnValidSubmit
    • Write a custom validation attribute and a cross-field rule