Table of Contents

Struct HtmxFieldValues

Namespace
Ramstack.HtmxToolkit
Assembly
Ramstack.HtmxToolkit.dll

Represents one or more values for a form field submitted with an HTMX request.

[JsonConverter(typeof(HtmxFieldValuesJsonConverter))]
public readonly struct HtmxFieldValues : IReadOnlyList<string>, IReadOnlyCollection<string>, IEnumerable<string>, IEnumerable
Implements
Inherited Members

Examples

// After archiving, reload the product list with its filters applied.
Response.Htmx(htmx => htmx.Location(Url.Action("Index", "Products")!, new HtmxLocationOptions
{
    Target = "#product-list",
    Values = new Dictionary<string, HtmxFieldValues>
    {
        ["status"] = "archived",          // One value.
        ["category"] = ["books", "music"] // Several values of one field.
    }
}));

Constructors

HtmxFieldValues(string?)

Initializes a new instance of the HtmxFieldValues structure with a single value.

public HtmxFieldValues(string? value)

Parameters

value string

The value to store, or null to represent no values.

HtmxFieldValues(string[]?)

Initializes a new instance of the HtmxFieldValues structure with the specified values.

public HtmxFieldValues(string[]? values)

Parameters

values string[]

The values to store, or null to represent no values.

Remarks

The specified array is stored directly and is not copied.

Properties

Count

Gets the number of elements in the collection.

public int Count { get; }

Property Value

int

The number of elements in the collection.

this[int]

Gets the element at the specified index in the read-only list.

public string this[int index] { get; }

Parameters

index int

The zero-based index of the element to get.

Property Value

string

The element at the specified index in the read-only list.

Methods

Create(ReadOnlySpan<string>)

Creates an HtmxFieldValues from the specified values.

public static HtmxFieldValues Create(ReadOnlySpan<string> values)

Parameters

values ReadOnlySpan<string>

The values to include.

Returns

HtmxFieldValues

An HtmxFieldValues containing the specified values.

GetEnumerator()

Returns an enumerator that iterates through the values.

public HtmxFieldValues.Enumerator GetEnumerator()

Returns

HtmxFieldValues.Enumerator

An enumerator for the values.

Operators

implicit operator HtmxFieldValues(string?)

Converts a string to an HtmxFieldValues.

public static implicit operator HtmxFieldValues(string? value)

Parameters

value string

The value to convert, or null to represent no values.

Returns

HtmxFieldValues

An HtmxFieldValues containing value.

implicit operator HtmxFieldValues(string[]?)

Converts an array of string values to an HtmxFieldValues.

public static implicit operator HtmxFieldValues(string[]? values)

Parameters

values string[]

The values to convert, or null to represent no values.

Returns

HtmxFieldValues

An HtmxFieldValues containing values.