Skip to content
Razor catalogue

On this page

@addTagHelper *, Webority.Ui.Razor

Try it

Press Save with an empty field to see the summary take focus and list every problem.

A form with two required fields
The server validates the submit and re-renders the values. Every field also shows its own message.
Show code
<form method="get" action="/Components/AppErrorSummary#try-it" novalidate>
    <input type="hidden" name="demo" value="1" />
    <app-error-summary>
        <app-error-summary-item field="demoName">Enter the company name.</app-error-summary-item>
        <app-error-summary-item field="demoEmail">Enter an email address like name@company.in</app-error-summary-item>
    </app-error-summary>
    <app-input label="Company name" name="demoName" required="true" error="Enter the company name." />
    <app-input label="Email" name="demoEmail" type="email" required="true" error="Enter an email address like name@company.in" />
    <app-button type="Submit">Save</app-button>
</form>

Basic

Use the default heading when the form only needs to say how many fields to fix.

Two errors, default title
The heading reads Fix 2 fields to continue. With one error it reads Fix 1 field to continue.
Show code
<app-error-summary auto-focus="false">
    <app-error-summary-item field="name">Enter the company name.</app-error-summary-item>
    <app-error-summary-item field="email">Enter an email address like name@company.in</app-error-summary-item>
</app-error-summary>

Custom title

Set a title when the form has its own wording, such as a save or a send.

A title that names the action
The list below it is unchanged.
Show code
<app-error-summary title="Fix 2 fields to save" auto-focus="false">
    <app-error-summary-item field="name">…</app-error-summary-item>
    <app-error-summary-item field="email">…</app-error-summary-item>
</app-error-summary>

Every option

Every value of every prop, one cell each.

errors

errors: one error

title

title omitted (default): the heading counts the fields
title="Check these fields before you send"

autoFocus

auto-focus (default true): takes focus when errors appear; off in this demo

id

id: names the summary, and its heading id is built from it

className

class="mb-0": adds a class to the summary element

from-model-state

from-model-state (default): lists only the items written inside
from-model-state="true": also lists the page's model errors

Guidance

What to do, and what to avoid.

Use it when

  • A form with more than one field failed to submit, and the reader needs to see everything wrong at once.
  • Keyboard and screen reader users should land on the list and reach each field from it.
  • You also show each field's own error, so the list and the fields agree.

Reach for something else when

  • You have one message that does not belong to a field. → AppAlert
  • The feedback is brief, such as Saved or Copied. → toast
  • The form has a single field. → that field's own error prop

Reference

Try every prop, read the full list, and check keyboard and screen reader behaviour.

React, generated from the controls
<AppErrorSummary
  autoFocus={false}
  errors={[
    { field: 'name', message: 'Enter the company name.' },
    { field: 'email', message: 'Enter an email address like name@company.in' },
  ]}
/>
Razor, the same props
<app-error-summary auto-focus="false">
    <app-error-summary-item field="name">Enter the company name.</app-error-summary-item>
    <app-error-summary-item field="email">Enter an email address like name@company.in</app-error-summary-item>
</app-error-summary>

7 props. The 2 most used come first.

Used on most screens 2 props

PropTypeDefaultDescription
titledefault Fix N fields to continue string Fix N fields to continue The heading. Defaults to Fix N fields to continue, or Fix 1 field to continue for one item.
auto-focusdefault true bool true Take focus when errors appear. Turn off only where the summary is shown for reference, such as documentation, never on a form.

Less common 5 props

PropTypeDefaultDescription
iddefault generated string generated DOM id of the summary; its heading id is built from it.
from-model-statedefault false bool false Lists every error in the page's ModelState after the items written inside, so a form page needs no loop. Each error links to its field by name; a whole-form error (the empty key) links to nothing.
classdefault - string - Extra classes merged onto the summary.
app-error-summary-item fielddefault - string - On an app-error-summary-item child: the id or name of the input to focus. A custom field focuses its inner control.
app-error-summary-item contentdefault - string - The element's text is the message and the link text. An empty item is left out. With no items the summary renders nothing.

Screen reader

3 notes
  • The summary has role alert and takes focus when errors appear, so a screen reader announces the title and the count.
  • Only the step from no errors to some errors takes focus, so a re-render while the user types a fix never pulls focus from the field.
  • Each message is a link that moves focus to its field by id or name; the plain anchor stays as the no-script fallback.