Table of Contents

Class HtmxUrlTagHelper

Namespace
Ramstack.HtmxToolkit.TagHelpers
Assembly
Ramstack.HtmxToolkit.dll

Generates URLs for HTMX request attributes on matching elements.

[HtmlTargetElement(Attributes = "hx-action")]
[HtmlTargetElement(Attributes = "hx-controller")]
[HtmlTargetElement(Attributes = "hx-area")]
[HtmlTargetElement(Attributes = "hx-page")]
[HtmlTargetElement(Attributes = "hx-page-handler")]
[HtmlTargetElement(Attributes = "hx-route")]
[HtmlTargetElement(Attributes = "hx-all-route-data")]
[HtmlTargetElement(Attributes = "hx-route-*")]
[HtmlTargetElement(Attributes = "hx-host")]
[HtmlTargetElement(Attributes = "hx-protocol")]
[HtmlTargetElement(Attributes = "hx-fragment")]
[RequiresUnreferencedCode("Razor Page URL generation is not compatible with trimming.")]
public sealed class HtmxUrlTagHelper : TagHelper, ITagHelper, ITagHelperComponent
Inheritance
HtmxUrlTagHelper
Implements
Inherited Members

Examples

@addTagHelper *, Ramstack.HtmxToolkit

<button hx-post
        hx-page="/Orders/Edit"
        hx-page-handler="Archive"
        hx-route-id="@Model.OrderId"
        hx-target="#order-status">
    Archive
</button>

@* For order 42, renders hx-post="/Orders/Edit?id=42&amp;handler=Archive". *@

Constructors

HtmxUrlTagHelper(IUrlHelperFactory)

Generates URLs for HTMX request attributes on matching elements.

public HtmxUrlTagHelper(IUrlHelperFactory factory)

Parameters

factory IUrlHelperFactory

The factory used to create URL helpers.

Properties

Action

Gets or sets the name of the action.

[HtmlAttributeName("hx-action")]
public string? Action { get; set; }

Property Value

string

Remarks

Must be null if Route, Page, or PageHandler is not null.

Area

Gets or sets the name of the area.

[HtmlAttributeName("hx-area")]
public string? Area { get; set; }

Property Value

string

Remarks

Can be combined with a named route, controller action, or Razor Page. When not null, overrides any area value in RouteValues.

Controller

Gets or sets the name of the controller.

[HtmlAttributeName("hx-controller")]
public string? Controller { get; set; }

Property Value

string

Remarks

Must be null if Route, Page, or PageHandler is not null.

Fragment

Gets or sets the URL fragment name.

[HtmlAttributeName("hx-fragment")]
public string? Fragment { get; set; }

Property Value

string

Host

Gets or sets the host name.

[HtmlAttributeName("hx-host")]
public string? Host { get; set; }

Property Value

string

Order

When a set of ITagHelpers are executed, their Init(TagHelperContext)'s are first invoked in the specified Order; then their ProcessAsync(TagHelperContext, TagHelperOutput)'s are invoked in the specified Order. Lower values are executed first.

public override int Order { get; }

Property Value

int

Remarks

Default order is 0.

Page

Gets or sets the name of the page.

[HtmlAttributeName("hx-page")]
public string? Page { get; set; }

Property Value

string

Remarks

Must be null if Route, Action, or Controller is not null.

PageHandler

Gets or sets the name of the page handler.

[HtmlAttributeName("hx-page-handler")]
public string? PageHandler { get; set; }

Property Value

string

Remarks

Must be null if Route, Action, or Controller is not null.

Protocol

Gets or sets the protocol for the URL, such as http or https.

[HtmlAttributeName("hx-protocol")]
public string? Protocol { get; set; }

Property Value

string

Route

Gets or sets the name of the route.

[HtmlAttributeName("hx-route")]
public string? Route { get; set; }

Property Value

string

Remarks

Must be null if Action, Controller, Page, or PageHandler is not null.

RouteValues

Gets or sets the additional route values.

[HtmlAttributeName("hx-all-route-data", DictionaryAttributePrefix = "hx-route-")]
public IDictionary<string, string> RouteValues { get; set; }

Property Value

IDictionary<string, string>

ViewContext

Gets or sets the view context for the current request.

[ViewContext]
[HtmlAttributeNotBound]
public ViewContext ViewContext { get; set; }

Property Value

ViewContext

Methods

ProcessAsync(TagHelperContext, TagHelperOutput)

Asynchronously executes the TagHelper with the given context and output.

public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)

Parameters

context TagHelperContext

Contains information associated with the current HTML tag.

output TagHelperOutput

A stateful HTML element used to generate an HTML tag.

Returns

Task

A Task that on completion updates the output.

Remarks

By default this calls into Process(TagHelperContext, TagHelperOutput).