Troubleshooting Guide
On this page
- Introduction
- Common Issues
- 1. HTMX Requests Not Working or Not Reaching the Server
- 2. HTMX Request Successful (200 OK) but UI Doesn’t Update Correctly
- 3. Antiforgery Validation Fails (400 Bad Request or Similar)
- 4. Validation Errors Are Not Displayed
- 5. Full Layout Renders During HTMX Partial Updates
- 6. Out‑of‑Band (OOB) Swaps Not Working
- 7. Streaming Rendering (
[StreamRendering]) Issues with HTMX - 8. An htmx extension does nothing
- 9. Console warning: “no on this page”
- Still Stuck?
Introduction
This guide covers common problems developers might encounter when using Rizzy and provides steps to diagnose and resolve them. Before diving into specific issues, always ensure you’ve checked:
- Browser Developer Tools:
- Console: Look for JavaScript errors (HTMX, Alpine.js, custom scripts).
- Network Tab: Inspect requests. Check the URL, method, status code (200 OK, 400 Bad Request, 404 Not Found, 500 Internal Server Error), request headers (especially
HX-Request), and response content/headers.
- Server Logs: Check your ASP.NET Core application logs for exceptions or warnings.
Common Issues
1. HTMX Requests Not Working or Not Reaching the Server
Symptoms:
- Clicking a button/element with
hx-get/hx-postdoes nothing. - Network tab shows no request being made.
- Network tab shows a 404 Not Found error for the request URL.
Diagnosis & Solutions:
- Is HTMX loaded? Ensure the HTMX JavaScript library is included correctly in your main layout (
AppLayout.razoror similar) before any elements try to usehx-*attributes. Check the browser console for errors related to HTMX loading. - Correct URL? Double-check the URL specified in
hx-get,hx-post, etc. Does it exactly match a defined route in your ASP.NET Core application (MVC action or Minimal API endpoint)? Pay attention to leading slashes (/) and case sensitivity if applicable. - Correct HTTP Method? Does the
hx-*attribute (hx-post) match the method expected by your server endpoint ([HttpPost],MapPost)? - Routing Configured? Verify your ASP.NET Core routing is correctly configured (
MapControllers(),MapGet(),MapPost(), etc.) inProgram.cs.
2. HTMX Request Successful (200 OK) but UI Doesn’t Update Correctly
Symptoms:
- Network tab shows a 200 OK response, but the target element doesn’t change.
- The wrong part of the page is updated.
- The entire page seems to reload instead of just a partial update.
Diagnosis & Solutions:
- Check Response Content: Examine the ‘Response’ tab in the Network tools for the successful request. Is the server returning the expected HTML fragment? If it’s returning a full HTML page, see Issue #5 below. If it’s returning JSON or something else unexpected, ensure your controller action is returning
PartialView<YourComponent>()or similar Rizzy result. - Check
hx-target: Is the CSS selector inhx-targetcorrect and does it uniquely identify an element already present in the DOM before the swap occurs? Use the browser’s element inspector to verify the selector. Common mistakes include typos or targeting an element that doesn’t exist yet. - Check
hx-swap: Is thehx-swapstyle appropriate?innerHTML(default) replaces the content inside the target, whileouterHTMLreplaces the target element itself. Other styles (beforeend,afterend, etc.) insert content relative to the target. Ensure the chosen style matches how your returned HTML fragment is structured. See SwapStyle docs. - HTMX Errors: Check the browser console for any specific errors reported by HTMX during the swap process.
- Valid HTML Fragment: Ensure the HTML returned by the server is valid. Malformed HTML can sometimes cause swapping to fail silently or partially.
3. Antiforgery Validation Fails (400 Bad Request or Similar)
Symptoms:
- POST, PUT, DELETE, or PATCH requests made via HTMX fail with a 400 Bad Request status code.
- Server logs might indicate an antiforgery token validation failure.
Diagnosis & Solutions:
- Middleware Order: Ensure
app.UseAntiforgery()is present inProgram.csand placed afterapp.UseRouting()and any authentication/authorization middleware (app.UseAuthentication(); app.UseAuthorization();). - Token on the page: rizzy.js reads the token from the
<meta name="htmx-config">tag and sends it in a header (RequestVerificationToken) on every htmx request that isn’t a GET. Check that:- Your root layout renders
<RzHeadOutlet />(not<HeadOutlet />) before the htmx script. If the tag is missing, rizzy.js logs a console warning that says so. Pages with their own<HeadContent>are fine. <RzScripts />(or your own htmx and/_content/Rizzy/js/rizzy.jsscript tags, htmx first, notype="module") is in the root layout.- The meta tag’s
antiforgeryentry has arequestToken(it is generated per page with the defaultRizzyConfig.AntiforgeryStrategy). - The request in the Network tab carries the
RequestVerificationTokenheader.
- Your root layout renders
- MVC registration:
[ValidateAntiForgeryToken]needsAddControllersWithViews()(orAddMvcCore().AddViews()). WithAddControllers()alone the attribute’s filter is not registered. - Minimal APIs: endpoints that bind form data are validated by
UseAntiforgery(); others need.WithMetadata(new RequireAntiforgeryTokenAttribute())orIAntiforgery.ValidateRequestAsync. - Cookie Present: Check browser developer tools (Application → Cookies) to ensure the antiforgery cookie (usually
.AspNetCore.Antiforgery.*) is present. - Cross-site posts on .NET 11: Rizzy rejects a cross-site post (
Sec-Fetch-Site: cross-siteorsame-site) with 400 before supplying it to[SupplyParameterFromForm]. If another origin must post to the endpoint, allow it with a CORS policy that hasAllowCredentials(), or opt the endpoint out with.DisableAntiforgery()/[IgnoreAntiforgeryToken].
4. Validation Errors Are Not Displayed
Symptoms:
- Form submission fails server-side validation (
ModelState.IsValidis false). - The controller returns the form component view again.
- No validation messages appear next to the fields or in the summary.
Diagnosis & Solutions:
- Correct Components Used?
- Is the form wrapped in an
<EditForm Model="@YourModel">? - Is
<DataAnnotationsValidator />placed inside theEditForm? - Is
<RzModelStateProvider />placed inside theEditForm? It copiesModelStateerrors into theEditContext. (RzInitialValidatoronly runs the Data Annotations validation; it does not readModelState.) - Are you using
<RzValidationMessageBase For="@(() => YourModel.PropertyName)" />for field‑specific messages? - Are you using
<RzValidationSummaryBase />for a summary?
- Is the form wrapped in an
- Check Response: Inspect the HTML response in the Network tab. Does it contain the expected validation message elements (e.g.,
<div class="validation-message field-validation-error" …>Your error</div>)? ModelStatePropagation:RzController’sView<T>/PartialView<T>pass the controller’sModelStateautomatically.IRizzyService(minimal APIs) has noModelStateof its own: pass aModelStateDictionarytoView/PartialView.- Was the response swapped? If you return status 422 (
Response.Htmx().ValidationFailed()), make sureHtmxConfig.NoSwapdoes not include"4xx", or route the response withhx-status:422="...". - Client‑Side Validation (Optional): If you expect client‑side validation messages before submitting, ensure:
- You have included a compatible JavaScript validation library (such as the
aspnet-validationscript included with RizzyUI, or jQuery Unobtrusive Validation). The Rizzy client script does not validate. - The
RzInput*Basecomponents are generating the necessarydata-val-*attributes (inspect the rendered HTML). This relies onDataAnnotationsProcessorand having Data Annotation attributes ([Required], etc.) on your model.
- You have included a compatible JavaScript validation library (such as the
5. Full Layout Renders During HTMX Partial Updates
Symptoms:
- An HTMX request intended to update only a small part of the page causes the entire site layout (header, footer, nav) to be rendered inside the target element.
Diagnosis & Solutions:
- Correct Rizzy Configuration: In
Program.cs, ensure:config.RootComponent = typeof(HtmxApp<YourAppLayout>);config.DefaultLayout = typeof(HtmxLayout<YourMainLayout>);(ReplaceYourAppLayoutandYourMainLayoutwith your actual layout component types). These wrappers are essential for detecting HTMX requests and suppressing the full layout rendering. See Getting Started.
- Is it an HTMX Request? Verify the request includes the
HX-Request: trueheader in the Network tab. If not, HTMX isn’t making the request correctly, or something is stripping the header. - Request type:
View<T>skips the layouts only for htmx requests that target one element (HX-Request-Type: partial). Boosted links that swap the whole<body>,hx-selectand back/forward restores sendHX-Request-Type: fulland get the full page on purpose. Give boosted links anhx-target(for examplehx-target:inherited="article"), or usePartialView<T>()for endpoints that only ever return fragments.
6. Out‑of‑Band (OOB) Swaps Not Working
Symptoms:
- An HTMX response is supposed to update multiple elements (the main target and others via OOB), but only the main target updates.
Diagnosis & Solutions:
- Check Response HTML: Inspect the raw HTML response in the Network tab. Does it contain elements with the
hx-swap-oob="true"(or other swap styles) attribute? These are the OOB elements. - Target IDs Exist: Does the
idattribute of the OOB element in the response match theidof an element already present in the main document before the swap happens? OOB swaps target existing elements by ID. - Rendered once:
View<T>/PartialView<T>render the queued content automatically. If you also placed<HtmxSwapContent />in a layout, remove it (the content would be rendered twice). See Out of Band Swapping. - Server Logic: Ensure your server‑side code (e.g., controller action) is correctly calling
IHtmxSwapService.AddSwappableComponent,AddSwappableFragment, etc., during the HTMX request lifecycle.
7. Streaming Rendering ([StreamRendering]) Issues with HTMX
Symptoms:
- A component with
[StreamRendering]loads initially via HTMX, showing a placeholder (“Loading…”). - The final content never appears, or JavaScript errors occur related to Blazor updates.
Diagnosis & Solutions:
- Rizzy script loaded? htmx 4 has no
hx-ext; the Rizzy client script registersrizzy-streamingwhen it loads. Load htmx first, then<script src="/_content/Rizzy/js/rizzy.js"></script>(notype="module"). - Extension allow-list: if you set
HtmxConfig.Extensions, it must includerizzy-streaming(and Rizzy’s other extensions:rizzy-antiforgery, rizzy-nonce, rizzy-confirm). - Content appears only at the end:
PartialView<T>sends a bare fragment, so the client waits for the whole stream. UseView<T>for progressive streaming. See Streaming Rendering with HTMX. - Check Console: Look for specific errors from Blazor’s streaming rendering JavaScript or the
rizzy-streamingextension.
8. An htmx extension does nothing
htmx skips an extension silently when its script did not load or when htmx.config.extensions does not name it (by its registered name: sse, not hx-sse). Enable extensions with HtmxConfig.UseExtensions(...) and render <RzScripts />; rizzy.js then warns on the console about a rejected extension or one that never registered. See Extensions.
9. Console warning: “no on this page”
rizzy.js checks the page when it loads. This warning means htmx has no Rizzy configuration and no antiforgery token. Render <RzHeadOutlet /> instead of <HeadOutlet /> in your root layout, before the htmx script. A second warning reports when the server runs a different Rizzy major version than the script (for example a cached CDN copy of rizzy.js). Set HtmxConfig.RizzyDiagnostics = false to silence these checks.
Still Stuck?
If you’ve worked through these steps and are still facing issues:
- Simplify your scenario to isolate the problem.
- Double-check the relevant Rizzy and HTMX documentation.
- Consider creating a minimal reproducible example.
- Seek help from the community (e.g., project’s GitHub Discussions/Issues, relevant forums). Provide clear details about the problem, what you’ve tried, relevant code snippets, and browser/server logs if possible.