Using in C#

Move rendering logic out of views when it becomes structural or reusable.

Overview

PageBuilder can be used directly from C# code, not only from Razor views. This is useful when HTML generation must be encapsulated in reusable classes, framework code, services, or rendering infrastructure.

Using PageBuilder in C# makes it possible to centralize rendering behavior while preserving the same attribute system, style system, builder lifecycle, and page model used in Razor-based rendering.

Why render in C#

Rendering directly in C# is especially useful when:

A rendering pattern must be reused across many views
A component needs its own encapsulated logic
Markup generation depends on application state or metadata
You are building framework-level components on top of PageBuilder
You are generating documentation or system pages automatically

Relationship with the rendering pipeline

Using builders in C# does not bypass the PageBuilder pipeline. Builders rendered in C# can still participate in the same page model as components rendered from Razor.

Same pipeline, different location

A builder created in C# can still register scripts, stylesheets, and other page-level dependencies through PageInformation while it renders. The page pipeline remains the same — only the location of the rendering logic changes.

Typical use cases

Reusable HTML builders
Layout infrastructure
Custom rendering helpers
Documentation pages
Higher-level component libraries

Why this matters

Once rendering logic moves into C#, it becomes easier to reuse, test, document, and evolve. This is one of the reasons PageBuilder works well as a foundation for larger rendering ecosystems. Instead of treating HTML generation as view-only logic, PageBuilder allows it to become part of the application architecture.

Recommended usage

Use C# builders for repeated or framework-level rendering logic
Keep them aligned with the shared page model
Let builders register their dependencies through PageInformation when needed
Keep the final page orchestration in the PageBuilder pipeline

Continue with Examples

See the rendering model applied to practical real-world scenarios.

Examples →