Table of Contents

Class HtmxValsTagHelper

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

Applies an hx-vals attribute assembled from strongly typed tag helper attributes.

[HtmlTargetElement(Attributes = "hx-vals-inherited")]
[HtmlTargetElement(Attributes = "hx-vals-append")]
[HtmlTargetElement(Attributes = "hx-all-vals")]
[HtmlTargetElement(Attributes = "hx-val-*")]
public sealed class HtmxValsTagHelper : TagHelper, ITagHelper, ITagHelperComponent
Inheritance
HtmxValsTagHelper
Implements
Inherited Members

Examples

@addTagHelper *, Ramstack.HtmxToolkit

<button hx-get="/reports/preview"
        hx-val-category="@Model.Category"
        hx-val-format="summary"
        hx-target="#preview">
    Preview
</button>

@* Renders hx-vals='{"category":"...","format":"summary"}' with the JSON built and escaped for you. *@

Remarks

  • HTMX 1.x and 2.x merge-inherit hx-vals from parent elements.
  • HTMX 4.x requires either the explicit inheritance modifier or the global ImplicitInheritance option for inheritance.
  • The append modifier merges a child declaration into inherited values.

Constructors

HtmxValsTagHelper(IOptions<HtmxToolkitOptions>)

Applies an hx-vals attribute assembled from strongly typed tag helper attributes.

public HtmxValsTagHelper(IOptions<HtmxToolkitOptions> options)

Parameters

options IOptions<HtmxToolkitOptions>

Remarks

  • HTMX 1.x and 2.x merge-inherit hx-vals from parent elements.
  • HTMX 4.x requires either the explicit inheritance modifier or the global ImplicitInheritance option for inheritance.
  • The append modifier merges a child declaration into inherited values.

Properties

Append

Gets or sets a value indicating whether hx-vals is appended to inherited values.

[HtmlAttributeName("hx-vals-append")]
public bool Append { get; set; }

Property Value

bool

Remarks

HTMX 4.x emits the append modifier when this property is true. The property does not change the generated attribute name for HTMX 1.x and 2.x.

Inherited

Gets or sets a value indicating whether hx-vals is explicitly inherited.

[HtmlAttributeName("hx-vals-inherited")]
public bool Inherited { get; set; }

Property Value

bool

Remarks

HTMX 1.x and 2.x merge-inherit values without a modifier. HTMX 4.x emits the inherited modifier when this property is true.

Values

Gets or sets the hx-vals attribute values.

[HtmlAttributeName("hx-all-vals", DictionaryAttributePrefix = "hx-val-")]
public IDictionary<string, string> Values { get; set; }

Property Value

IDictionary<string, string>

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).