Table of Contents

Class OobResultFilterBase<T>

Namespace
Htmx.Components.Filters
Assembly
Htmx.Components.dll

Base class for result filters that handle out-of-band (OOB) updates in HTMX responses. This abstract class provides the common infrastructure for processing attributes that trigger additional view renders to be included in HTMX responses for updating multiple page elements.

public abstract class OobResultFilterBase<T> : IAsyncResultFilter, IFilterMetadata where T : Attribute

Type Parameters

T

The attribute type that triggers the OOB behavior.

Inheritance
OobResultFilterBase<T>
Implements
Derived
Inherited Members
Extension Methods

Remarks

Derived classes only need to implement view name retrieval and multi-swap update logic. The base class handles the detection of HTMX requests, attribute processing, and result transformation. For non-HTMX requests, it can optionally render a full page view if implemented by the derived class.

Creating Custom OOB Filters:

This base class is designed to be extended for custom components that need coordinated updates. Common scenarios include:

  • Authentication-related components that need to refresh together
  • Navigation and breadcrumb components that depend on current context
  • Dashboard widgets that need to reflect data changes
  • Shopping cart and inventory displays that must stay synchronized

To create a custom filter, inherit from this class with your custom attribute type and implement the abstract methods to define your specific OOB update behavior.

Methods

GetViewNameForNonHtmxRequest(T, ControllerActionDescriptor)

Gets the view name to render for non-HTMX requests when the action has the target attribute. The default implementation returns null, which means no special handling for non-HTMX requests.

protected virtual Task<string?> GetViewNameForNonHtmxRequest(T attribute, ControllerActionDescriptor cad)

Parameters

attribute T

The attribute instance found on the action method.

cad ControllerActionDescriptor

The controller action descriptor for the current action.

Returns

Task<string>

A task that represents the asynchronous operation. The task result contains the view name, or null if no special view should be rendered.

Remarks

Derived classes should override this method if they need to provide a specific view for non-HTMX requests. If the filter should not handle non-HTMX requests at all, this method can be overridden to throw an exception.

OnResultExecutionAsync(ResultExecutingContext, ResultExecutionDelegate)

Executes the result filter logic, processing actions marked with the target attribute type. For HTMX requests, converts the result to a MultiSwapViewResult with OOB updates. For non-HTMX requests, optionally renders a full page view if implemented by the derived class.

public Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)

Parameters

context ResultExecutingContext

The result executing context.

next ResultExecutionDelegate

The next filter in the pipeline.

Returns

Task

A task representing the asynchronous operation.

UpdateMultiSwapViewResultAsync(T, MultiSwapViewResult, ResultExecutingContext)

Updates the MultiSwapViewResult with additional view renders based on the attribute configuration. This method is called for HTMX requests and should add any necessary out-of-band updates.

protected abstract Task UpdateMultiSwapViewResultAsync(T attribute, MultiSwapViewResult multiSwapViewResult, ResultExecutingContext context)

Parameters

attribute T

The attribute instance found on the action method.

multiSwapViewResult MultiSwapViewResult

The MultiSwapViewResult to update with additional renders.

context ResultExecutingContext

The result executing context for accessing request and controller information.

Returns

Task

A task representing the asynchronous update operation.