diff --git a/docs/articles/responses.md b/docs/articles/responses.md index b4c3130..d9e382d 100644 --- a/docs/articles/responses.md +++ b/docs/articles/responses.md @@ -269,6 +269,12 @@ public IActionResult Inventory(string sku) => The attribute supports `Refresh`, `Reswap`, `ReswapExpression`, `Retarget`, and `Reselect`. Use the fluent API when values depend on runtime state or when triggering events and navigation. +Apply the attribute to an action, a controller, or a Razor Pages page model. +Razor Pages ignore filter attributes on handler methods, so put it on the page model class. +When a controller and its action specify the same header, the action's value takes effect. +A derived class inherits the attribute from its base class; an attribute declared on the derived class +replaces the inherited one entirely. + ## Access headers directly Use `Response.GetHtmxHeaders()` when middleware or shared infrastructure needs property access instead of fluent chaining: diff --git a/src/Ramstack.HtmxToolkit/HtmxResponseAttribute.cs b/src/Ramstack.HtmxToolkit/HtmxResponseAttribute.cs index b54e996..2d8c48e 100644 --- a/src/Ramstack.HtmxToolkit/HtmxResponseAttribute.cs +++ b/src/Ramstack.HtmxToolkit/HtmxResponseAttribute.cs @@ -11,11 +11,23 @@ namespace Ramstack.HtmxToolkit; /// Specifies HTMX response headers to apply when an action result is executed for an HTMX request. /// /// -/// A property that is not set, or is set to , , -/// or an empty string, adds no header. The specified headers replace any values that the action -/// has already set for them. +/// +/// A property that is not set, or is set to , , +/// or an empty string, adds no header. The specified headers replace any values that the action +/// has already set for them. +/// +/// +/// The attribute can be applied to an action, a controller, or a Razor Pages page model. +/// Razor Pages ignore filter attributes on handler methods, so apply it to the page model class. +/// When both a controller and its action specify the same header, the action's value takes effect. +/// +/// +/// A derived controller or page model inherits the attribute from its base class. +/// If the derived class declares its own attribute, that attribute replaces the inherited one, +/// including the headers that only the inherited attribute specifies. +/// /// -[AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)] +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)] public sealed class HtmxResponseAttribute : Attribute, IResultFilter { private readonly List<(string Key, string Value)> _headers = [];