liveBook · Manning

Generic template component

As explained in Pro ASP.NET Core 7, Tenth Edition

A generic template component is a reusable Blazor component parameterized by a data type and a rendering template for values of that type.

A generic template component is a reusable Blazor component parameterized by a data type and a rendering template. It receives a sequence of typed objects, generates content for each object, and can add shared behavior such as sorting or highlighting. section 34.3.2

Define the component around three pieces:

  • @typeparam RowType declares the row data type. section 34.3.2
  • A RowData parameter of type IEnumerable<RowType> supplies the values. section 34.3.2

Reusable people table

Use <TableTemplate RowType="Person" RowData="People"> with a Header fragment and a RowTemplate Context="p". The same component can then render departments by changing the type, data sequence, and row markup.

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Explains generic parameters, typed data, render fragments, iteration, and added sorting or highlighting features.
Examples
Uses people and department tables with headers, contextual row templates, related data, sorting, and location-based highlighting.
What it assumes
Assumes basic Blazor component syntax and C# collections while introducing generic parameters and RenderFragment<T> usage.
What you can do after
Build it from scratch as a typed Blazor component and reuse it for different entity collections and row templates.
How it connects
Connects generic type parameters with Blazor components, RenderFragment, data binding, sorting, and highlighting.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.