Class PageStateTagHelper
- Namespace
- Htmx.Components.TagHelpers
- Assembly
- Htmx.Components.dll
A tag helper that renders the encrypted page state as a hidden input field within a container div. This tag helper enables page state persistence across HTMX requests by embedding the state data in the HTML.
[HtmlTargetElement("htmx-page-state")]
public class PageStateTagHelper : TagHelper, ITagHelper, ITagHelperComponent
- Inheritance
-
PageStateTagHelper
- Implements
- Inherited Members
- Extension Methods
Examples
Usage in Razor views:
<htmx-page-state container-id="my-state-container" />
Remarks
The tag helper renders a div container with a hidden input field containing the encrypted page state. The container can be targeted by HTMX for out-of-band updates to refresh the page state.
Constructors
PageStateTagHelper(IPageState)
Initializes a new instance of the PageStateTagHelper class.
public PageStateTagHelper(IPageState pageState)
Parameters
pageState
IPageStateThe page state service that provides the encrypted state data.
Properties
ContainerId
Gets or sets the HTML ID for the container div element. This ID can be used for HTMX targeting and CSS styling.
public string ContainerId { get; set; }
Property Value
- string
The container div ID. Defaults to 'page_state_container'.
Methods
Process(TagHelperContext, TagHelperOutput)
Processes the tag helper and renders the page state container with a hidden input field.
public override void Process(TagHelperContext context, TagHelperOutput output)
Parameters
context
TagHelperContextThe tag helper context.
output
TagHelperOutputThe tag helper output to modify.