Skip to content
Proyectos

Acerca de

Añade métodos de extensión a HttpResponse y HttpRequest para facilitar el trabajo con Htmx.

Otros proyectos

Cómo se miden estas cifras

Crecimiento de estrellas medido

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
Recopilando historial

Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.

README.md

Original

htmx.NET

HTMX Logo

Htmx Htmx.TagHelpers

[!IMPORTANT] htmx.NET 2.x targets htmx 4 only. It is a breaking change from the 1.x line (which supports htmx 1.x/2.x). See the Migration guide. Staying on htmx 1/2? Use htmx.NET 1.x and the previous-version docs.

[!NOTE] 2.0.0 is in preview. Install it with --prerelease and kick the tires — then please share feedback on GitHub issues before the stable release.

Server-side ASP.NET Core helpers that make working with htmx from HttpRequest and HttpResponse simpler, plus Tag Helpers for URL generation, htmx-config, and antiforgery.

📖 Full documentation: khalidabuhakmeh.github.io/Htmx.Net

Install

While 2.x is in preview, add --prerelease:

dotnet add package Htmx --prerelease
dotnet add package Htmx.TagHelpers --prerelease

Requires htmx 4 on the client:

<script src="https://unpkg.com/[email protected]/dist/htmx.min.js" defer></script>

Quick start

Detect htmx requests and return a partial instead of a full page:

// in a Razor Page or controller
return Request.IsHtmx()
    ? Partial("_Form", this)
    : Page();

Read typed htmx request headers (the HX-Source element reference, request type, and more):

if (Request.IsHtmx(out var headers))
{
    var source = headers.SourceElement;   // tag#id, e.g. button#save
    var kind   = headers.RequestType;     // Full or Partial
}

Set htmx response headers with a fluent API:

Response.Htmx(h => h
    .PushUrl("/new-url")
    .Retarget("#result")
    .Reswap(HtmxSwap.OuterMorph)
    .WithTrigger("saved", new { id = 42 }));

Tag Helpers — add to _ViewImports.cshtml:

@addTagHelper *, Htmx.TagHelpers

Generate ASP.NET Core URLs straight onto htmx attributes, and configure htmx + antiforgery:

<meta name="htmx-config" includeAspNetAntiforgeryToken="true" defaultSwap="innerHTML" />

<button hx-get hxn-page="Index" hxn-page-handler="Snippet" hx-target="#result">
    Load
</button>
// Program.cs — expose the antiforgery integration script
app.MapHtmxAntiforgeryScript();

Documentation

New to htmx with ASP.NET Core? See the JetBrains guide to getting started with htmx for ASP.NET Core developers.

License

Copyright (c) Khalid Abuhakmeh. Licensed under the MIT License — see License.md.

Explorar proyectos relacionados

Cargando…