Core Feature
SwapState
UI state without client-side stores. Pagination, filters, tabs—managed on the server.
The Problem
In SPAs, state management is complex. Redux, Context, Signals—all exist to synchronize client state with server data.
The Solution
The server is the single source of truth. State is serialized into hidden inputs and travels with each request.
1. Define Your State
public class FilterState : SwapState
{
public string Group { get; set; } = "all";
public bool ShowCompleted { get; set; } = false;
}
2. Render & Bind
<swap-state state="Model.State" />
public IActionResult Filter([FromSwapState] FilterState state)
Use Cases
Pagination
Track page number across requests
Filters
Persist search and sort
Tabs
Remember active tab
Wizards
Multi-step form state
Key Components
- SwapState base class
- <swap-state> tag helper
- [FromSwapState] attribute
- .WithState() method