NetMX.Htmx
0.1.0-alpha
dotnet add package NetMX.Htmx --version 0.1.0-alpha
NuGet\Install-Package NetMX.Htmx -Version 0.1.0-alpha
<PackageReference Include="NetMX.Htmx" Version="0.1.0-alpha" />
<PackageVersion Include="NetMX.Htmx" Version="0.1.0-alpha" />
<PackageReference Include="NetMX.Htmx" />
paket add NetMX.Htmx --version 0.1.0-alpha
#r "nuget: NetMX.Htmx, 0.1.0-alpha"
#:package NetMX.Htmx@0.1.0-alpha
#addin nuget:?package=NetMX.Htmx&version=0.1.0-alpha&prerelease
#tool nuget:?package=NetMX.Htmx&version=0.1.0-alpha&prerelease
NetMX.Htmx
Strongly-typed C# helpers for working with HTMX in ASP.NET Core applications.
Overview
This package provides type-safe C# APIs for working with HTMX, eliminating magic strings and providing IntelliSense support for HTMX features.
Philosophy
- Views use raw HTMX attributes - Keep your Razor views clean with standard HTMX syntax
- Controllers use typed helpers - Get compile-time safety and IntelliSense in your C# code
- No magic - Simple wrappers around HTMX headers and conventions
Features
Response Helpers
Use HtmxResponse static methods in your controllers:
public IActionResult DeleteUser(Guid id)
{
// Delete user logic...
// Trigger a client-side event
HtmxResponse.Trigger(this, "userDeleted", new { userId = id });
// Retarget to a different element
HtmxResponse.Retarget(this, "#user-list");
// Change swap strategy
HtmxResponse.Reswap(this, HtmxSwap.OuterHTML);
return PartialView("_UserRow", nextUser);
}
Available methods:
Trigger()- Trigger client-side eventsTriggerAfterSettle()/TriggerAfterSwap()- Control event timingPushUrl()/ReplaceUrl()- Update browser historyRetarget()- Change target elementReswap()- Change swap strategyRedirect()- Client-side redirectRefresh()- Full page refresh
Request Helpers
Check for HTMX requests and access HTMX headers:
public IActionResult Index()
{
if (Request.IsHtmx())
{
// Return partial view for HTMX requests
return PartialView("_UserList", users);
}
// Return full page for regular requests
return View(users);
}
public IActionResult GetDetails(Guid id)
{
var targetId = Request.GetTargetId();
var triggerId = Request.GetTriggerId();
// Use HTMX headers to customize response...
}
Swap Strategies
Type-safe enum for HTMX swap strategies:
HtmxResponse.Reswap(this, HtmxSwap.OuterHTML); // Replace entire element
HtmxResponse.Reswap(this, HtmxSwap.BeforeEnd); // Append to container
HtmxResponse.Reswap(this, HtmxSwap.Delete); // Delete element
Usage Example
View (Razor) - Raw HTMX:
<button hx-delete="/users/@user.Id"
hx-target="#user-row-@user.Id"
hx-swap="outerHTML"
hx-confirm="Are you sure?">
Delete
</button>
Controller - Typed Helpers:
[HttpDelete("/users/{id}")]
public IActionResult Delete(Guid id)
{
_userService.Delete(id);
// Strongly typed, IntelliSense-friendly
HtmxResponse.Trigger(this, "userDeleted", new { userId = id });
HtmxResponse.Reswap(this, HtmxSwap.Delete);
return Ok();
}
Event-Driven Components
Use HTMX events for component communication:
Trigger event from controller:
HtmxResponse.Trigger(this, "user:created", new {
userId = newUser.Id,
userName = newUser.FullName
});
Listen in view:
<div id="user-stats"
hx-get="/api/users/stats"
hx-trigger="user:created from:body">
</div>
Integration
Add to your project:
dotnet add package NetMX.Htmx
No additional configuration needed - just start using the helpers!
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|