Table of Contents

Class ActionContextExtensions

Namespace
Htmx.Components.Extensions
Assembly
Htmx.Components.dll

Provides extension methods for creating valid ActionContext instances from the current request.

public static class ActionContextExtensions
Inheritance
ActionContextExtensions
Inherited Members

Methods

GetValidActionContext(IHttpContextAccessor)

Provides a sanity check to fail early if the current request context is not initialized.

public static ActionContext GetValidActionContext(this IHttpContextAccessor httpContextAccessor)

Parameters

httpContextAccessor IHttpContextAccessor

The HTTP context accessor to validate.

Returns

ActionContext

A valid ActionContext instance.

Remarks

This method uses endpoint routing metadata to recover the current MVC ActionDescriptor.

Exceptions

InvalidOperationException

Thrown when any of the following conditions are true:

  • HttpContext is not available
  • RouteData is not available
  • ActionDescriptor is not available
ArgumentNullException

Thrown when httpContextAccessor is null.

GetValidActionContext(IActionContextAccessor)

Provides a sanity check to fail early if IActionContextAccessor is not initialized.

[Obsolete("IActionContextAccessor is obsolete in ASP.NET Core 10. Use IHttpContextAccessor with GetValidActionContext() instead.", DiagnosticId = "ASPDEPR006", UrlFormat = "https://aka.ms/aspnet/deprecate/006")]
public static ActionContext GetValidActionContext(this IActionContextAccessor actionContextAccessor)

Parameters

actionContextAccessor IActionContextAccessor

The action context accessor to validate.

Returns

ActionContext

A valid ActionContext instance.

Exceptions

InvalidOperationException

Thrown when HttpContext, RouteData, or ActionDescriptor is not available.

ArgumentNullException

Thrown when actionContextAccessor is null.