Table of Contents

Struct HtmxResponseHeaders

Namespace
Ramstack.HtmxToolkit
Assembly
Ramstack.HtmxToolkit.dll

Represents strongly typed HTMX response headers.

public readonly struct HtmxResponseHeaders
Inherited Members

Properties

Location

Gets or sets the value of the HX-Location header, which performs a client-side redirect without a full-page reload.

public string? Location { get; set; }

Property Value

string

Remarks

If the header is not present, the property returns null. Assigning null or an empty string removes the header.

PushUrl

Gets or sets the value of the HX-Push-Url header, which pushes a new URL onto the browser's history stack.

public string? PushUrl { get; set; }

Property Value

string

Remarks

If the header is not present, the property returns null. Assigning null or an empty string removes the header.

Unlike PushUrl(string), setting this property does not remove the HX-Replace-Url header or the legacy HX-Push header.

Redirect

Gets or sets the value of the HX-Redirect header, which performs a client-side redirect with a full-page reload.

public string? Redirect { get; set; }

Property Value

string

Remarks

If the header is not present, the property returns null. Assigning null or an empty string removes the header.

Refresh

Gets or sets a value indicating whether the HX-Refresh header requests a full-page refresh.

public bool Refresh { get; set; }

Property Value

bool

Remarks

Assigning false removes the header.

ReplaceUrl

Gets or sets the value of the HX-Replace-Url header, which replaces the current URL without pushing a new entry to the browser's history stack.

public string? ReplaceUrl { get; set; }

Property Value

string

Remarks

If the header is not present, the property returns null. Assigning null or an empty string removes the header.

Unlike ReplaceUrl(string), setting this property does not remove the HX-Push-Url header or the legacy HX-Push header.

Reselect

Gets or sets the CSS selector specified by the HX-Reselect header to determine which part of the response is swapped in.

public string? Reselect { get; set; }

Property Value

string

Remarks

If the header is not present, the property returns null. Assigning null or an empty string removes the header.

Reswap

Gets or sets the swap style specified by the HX-Reswap header.

public HtmxSwap? Reswap { get; set; }

Property Value

HtmxSwap?

Remarks

Reads the style from ReswapExpression, or returns null if the header is not present or the style is not recognized. Assigning a style replaces the complete header value, including any modifiers. Assigning null removes the header.

ReswapExpression

Gets or sets the complete HX-Reswap header value, including any swap modifiers.

public string? ReswapExpression { get; set; }

Property Value

string

Remarks

If the header is not present, the property returns null. Assigning null or an empty string removes the header.

Retarget

Gets or sets the CSS selector specified by the HX-Retarget header to change the target of the content update.

public string? Retarget { get; set; }

Property Value

string

Remarks

If the header is not present, the property returns null. Assigning null or an empty string removes the header.

Trigger

Gets the client-side events to trigger through the HX-Trigger header.

public IReadOnlyList<KeyValuePair<string, string>>? Trigger { get; }

Property Value

IReadOnlyList<KeyValuePair<string, string>>

Remarks

Each entry pairs an event name with its detail serialized as JSON. Events are listed in the order they were added, including repeated names. The list is a read-only live view of the events added for the current response. The header is updated each time an event is added. If no events have been added, or the header has been removed, for example by Clear(HttpResponse), the property returns null.

HTMX 1.9.x and 2.x trigger these events when the response is received, whereas HTMX 4.x triggers them when the request completes (after the swap and settle steps whenever a swap is performed). In HTMX 4.x, the list also includes the events added with other timings, because all timings share the HX-Trigger header.

TriggerAfterSettle

Gets the client-side events to trigger through the HX-Trigger-After-Settle header after the settle step.

public IReadOnlyList<KeyValuePair<string, string>>? TriggerAfterSettle { get; }

Property Value

IReadOnlyList<KeyValuePair<string, string>>

Remarks

Each entry pairs an event name with its detail serialized as JSON. Events are listed in the order they were added, including repeated names. The list is a read-only live view of the events added for the current response. The header is updated each time an event is added. If no events have been added, or the header has been removed, for example by Clear(HttpResponse), the property returns null.

HTMX 4.x has no HX-Trigger-After-Settle header, so these events are emitted through HX-Trigger when the request completes (after the swap and settle steps whenever a swap is performed). The property therefore returns the same list as Trigger, including the events added with other timings.

TriggerAfterSwap

Gets the client-side events to trigger through the HX-Trigger-After-Swap header after the swap step.

public IReadOnlyList<KeyValuePair<string, string>>? TriggerAfterSwap { get; }

Property Value

IReadOnlyList<KeyValuePair<string, string>>

Remarks

Each entry pairs an event name with its detail serialized as JSON. Events are listed in the order they were added, including repeated names. The list is a read-only live view of the events added for the current response. The header is updated each time an event is added. If no events have been added, or the header has been removed, for example by Clear(HttpResponse), the property returns null.

HTMX 4.x has no HX-Trigger-After-Swap header, so these events are emitted through HX-Trigger when the request completes (after the swap and settle steps whenever a swap is performed). The property therefore returns the same list as Trigger, including the events added with other timings.