Skip to content

htmx.NET

Typed server-side helpers for htmx 4 in ASP.NET Core.
Terminal window
dotnet add package Htmx --prerelease
dotnet add package Htmx.TagHelpers --prerelease

Preview · net8.0 & net10.0 · targets htmx 4.0.0 · MIT

htmx sends its state in request headers and reads it back from response headers. htmx.NET turns both sides into typed C# — so you detect htmx requests, read the triggering element, set HX-* response headers, and generate URLs from ASP.NET routing, instead of parsing and concatenating strings by hand.

Read the incoming htmx request and answer with typed response headers, instead of parsing strings and building JSON by hand.

// Detect an htmx request and read the element that triggered it.
if (Request.IsHtmx(out var htmx))
{
// e.g. "save-button"
var id = htmx.SourceElement?.Id;
// Full or Partial
var type = htmx.RequestType;
}
// Set HX-* response headers fluently instead of building strings.
Response.Htmx(h => h
.PushUrl("/items/5")
.WithTrigger("saved", new { id = 5 }));