What are generic components in Blazor, and how does the @typeparam directive work?

Last updated 5 July 2026

  • Generic components are reusable UI components typed over one or more type parameters, so the same component works with any data type in a type-safe way (like List<T> for UI).

  • Declare them with @typeparam TItem (optionally with a where constraint), then use TItem in parameters like IEnumerable<TItem> and RenderFragment<TItem>.

  • Blazor usually infers the type from supplied parameters. Otherwise specify it explicitly (e.g. TItem="Person").

  • https://learn.microsoft.com/en-us/aspnet/core/blazor/components/generic-type-support?view=aspnetcore-10.0
  • https://learn.microsoft.com/en-us/aspnet/core/blazor/components/templated-components?view=aspnetcore-10.0
  • https://learn.microsoft.com/en-us/aspnet/core/mvc/views/razor?view=aspnetcore-10.0
  • https://blazor-university.com/templating-components-with-renderfragements/using-typeparam-to-create-generic-components/
  • https://levelup.gitconnected.com/types-of-blazor-components-4a81fe6c3f3f
  • https://www.michaelmarino.dev/blog/function-parameters/
All Blazor interview questions