Table of Contents

Struct HtmxRequestHeaders

Namespace
Ramstack.HtmxToolkit
Assembly
Ramstack.HtmxToolkit.dll

Represents strongly typed HTMX request headers.

public readonly struct HtmxRequestHeaders
Inherited Members

Properties

Boosted

Gets a value indicating whether the request came from a link or form enhanced with hx-boost.

public bool Boosted { get; }

Property Value

bool

Remarks

The header name is Boosted.

CurrentUrl

Gets the current URL of the browser.

public string? CurrentUrl { get; }

Property Value

string

Remarks

The header name is CurrentUrl.

HistoryRestoreRequest

Gets a value indicating whether the request fetches content for history restoration.

public bool HistoryRestoreRequest { get; }

Property Value

bool

Remarks

The header name is HistoryRestoreRequest.

HTMX 1.x and 2.x send this header after a history cache miss. HTMX 4.x refetches history content by default; local caching requires an extension.

Prompt

Gets the user's response to an hx-prompt on the client.

public string? Prompt { get; }

Property Value

string

Remarks

The header name is Prompt.

Supported natively in HTMX 1.x and 2.x. In HTMX 4.x, the hx-prompt extension restores this header.

Request

Gets a value indicating whether the current request is an HTMX request.

public bool Request { get; }

Property Value

bool

Remarks

The header name is Request.

RequestType

Gets the type of the expected response, either a partial or a full page.

public HtmxRequestType RequestType { get; }

Property Value

HtmxRequestType

Remarks

The header name is RequestType.

The value is "partial" for targeted swaps and "full" for body-level or hx-select requests. HTMX 4.x sends the header itself; for HTMX 1.x and 2.x, the companion script htmx-toolkit.js adds it.

A history restoration request without the header is reported as Full, because HTMX restores the whole page from it.

Source

Gets the identifier of the element that triggered the request.

public string? Source { get; }

Property Value

string

Remarks

The header name is Source.

Supported only in HTMX 4.x. The value contains the lowercase tag name and, when the element has an ID, # followed by its URI-encoded ID. Examples include button#submit and button.

Target

Gets the identifier of the target element, if present.

public string? Target { get; }

Property Value

string

Remarks

The header name is Target.

In HTMX 1.x and 2.x, the value is the ID of the target element.

In HTMX 4.x, the value contains the lowercase tag name and, when the element has an ID, # followed by its URI-encoded ID. Examples include div#results and body.

Trigger

Gets the ID of the element that issued the request, if present.

public string? Trigger { get; }

Property Value

string

Remarks

The header name is Trigger.

Supported only in HTMX 1.x and 2.x; HTMX 4.x identifies the source element with HX-Source instead.

TriggerName

Gets the name attribute of the element that issued the request, if present.

public string? TriggerName { get; }

Property Value

string

Remarks

The header name is TriggerName.

Supported only in HTMX 1.x and 2.x; HTMX 4.x identifies the source element with HX-Source instead.