liveBook · Manning

Chapter 18: Building forms with Tag Helpers

What you will learn in chapter 18 of ASP.NET Core in Action, 3e

This chapter introduces Tag Helpers as Razor features that generate and enhance server-rendered HTML, especially user-friendly forms that bind and validate data correctly.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This chapter introduces Tag Helpers as Razor features that generate and enhance server-rendered HTML, especially user-friendly forms that bind and validate data correctly.

Key terms: Tag Helpers, Razor, Razor templates, HTML, model binding, binding model, names, IDs, DataAnnotations, validation

18.1 Catering to editors with Tag Helpers

This section introduces Tag Helpers as HTML-like Razor features that connect server-side model metadata and values to generated form markup while remaining editor-friendly and simpler than WebForms controls.

Key terms: Tag Helpers, asp-*, Razor templates, PageModel, asp-for, DataAnnotations, view model, model binding, Validation Tag Helper, standard HTML syntax

18.2 Creating forms using Tag Helpers

This section introduces how form Tag Helpers generate model-bound HTML for Razor Pages while allowing developers to retain control over the resulting markup.

Key terms: Tag Helpers, PageModel, UserBindingModel, Input property, DataAnnotations, model binding, model validation, metadata, data-* attributes, raw HTML

18.2.1 The Form Tag Helper

This section explains how the Form Tag Helper generates form submission URLs, supplies route and handler values, and adds antiforgery support for Razor Pages forms.

Key terms: Form Tag Helper, FormTagHelper, asp-page, action attribute, method="post", GET, POST, Razor Pages, asp-route-*, asp-route-id

18.2.2 The Label Tag Helper

This section shows how the Label Tag Helper generates accessible labels from PageModel properties and their display metadata.

Key terms: Label Tag Helper, asp-for, [Display], PageModel, for attribute, ID, accessibility, screen reader, Tag Helpers, child objects

18.2.3 The Input and Textarea Tag Helpers

This section shows how the Input and Textarea Tag Helpers generate correctly bound, formatted, and validated form controls from model-property metadata.

Key terms: Input Tag Helper, asp-for, DataAnnotations, EmailAddress, input type, id, name, model binding, data-val-*, client-side validation

18.2.4 The Select Tag Helper

This section shows how to generate and bind single-select, multi-select, grouped, and optional-value HTML select controls with the Select Tag Helper.

Key terms: Select Tag Helper, asp-for, asp-items, SelectListItem, Value, Text, IEnumerable, MultiValues, multiple, Group

18.2.5 The Validation Message and Validation Summary Tag Helpers

This section shows how Validation Message and Validation Summary Tag Helpers display property-level and model-level validation errors in forms.

Key terms: Validation Message Tag Helper, asp-validation-for, ModelState, client-side validation, server-side validation, Validation Summary Tag Helper, asp-validation-summary, ValidationSummary, model-level errors, ModelOnly

18.3 Generating links with the Anchor Tag Helper

This section shows how the Anchor Tag Helper generates Razor Page links through routing instead of hardcoded href URLs.

Key terms: Anchor Tag Helper, asp-page, asp-page-handler, asp-route-*, Razor Page, routing, asp-area, asp-host, asp-protocol, absolute URL

18.4 Cache-busting with the Append Version Tag Helper

This section explains how the Append Version Tag Helper automatically cache-busts static assets so browsers receive changed files while still caching unchanged ones.

Key terms: static assets, browser cache, cache-busting query string, query parameter, Append Version Tag Helper, asp-append-version, hash

18.5 Using conditional markup with the Environment Tag Helper

This section shows how to render environment-specific Razor markup declaratively with the Environment Tag Helper instead of an inline C# condition.

Key terms: development environment, production environment, testing environment, Razor templates, EnvironmentTagHelper, Tag Helper, hosting environment, declarative, C# markup

18.6 Summary

This summary recaps how built-in Tag Helpers generate model-bound forms, routed links, cache-aware assets, and environment-specific server-rendered HTML.

Where this is used later

Concepts explained in this chapter

← Chapter 17: Rendering HTML using Razor views Chapter 19: Creating a website with MVC controllers →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.