khalidabuhakmeh/Htmx.Net
Tentang
Menambahkan metode ekstensi ke HttpResponse dan HttpRequest untuk memudahkan penggunaan Htmx.
Proyek lainnyaPertumbuhan bintang terukur
- dalam 24 jam
- 0
- dalam 7 hari
- 0
- dalam 15 hari
- 0
- dalam 1 bulan
- Mengumpulkan riwayat
Perubahan bersih pada periode yang tumpang tindih, bukan total harian. Pengukuran yang belum tersedia dibiarkan kosong. Bintang menunjukkan perhatian, bukan kualitas.
README.md
Aslihtmx.NET

[!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
--prereleaseand 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
- Getting started
- Guides — request detection, response headers, triggers, config, Tag Helpers, antiforgery, caching, partials & morph
- Migration guide (v1 → v2)
- Previous version (v1.x)
- Samples:
samples/Htmx4.Sampledemonstrates every feature with integration and Playwright E2E tests. - More samples: Twelve Days of htmx-mas — a Christmas-themed ASP.NET Core app with 12 htmx demos.
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.
Jelajahi proyek terkait
Memuat…