Back to Practical Aspnetcore

HTMX hx-swap-oob to perform out of band swap

projects/htmx/swap-2/README.md

latest613 B
Original Source

HTMX hx-swap-oob to perform out of band swap

This example shows how to enable out of band swap using hx-swap-oob (doc).

The attribute is used in the response by the server.

csharp
    return key switch 
    {
        "innerHtml" => Results.Content($"""
        Hello {DateTime.UtcNow}. <p>Because this is hxSwap="innerHTML", you can keep clicking and the swap keeps working. Check the date. </p>
        <div id="oob-target" hx-swap-oob="true">New out of band message {DateTime.UtcNow}</div>
        """),
        _ => Results.Content("")
    };