Anonymous or Substitute Handlers
Introduction
Sometimes, it is required to get a partial without declaring a handler. This is when anonymous handlers became handy.
The model.Partial
will contain the returned new Page()
and all the responses from all the apps mapped to the "/custom-url"
. The anonymous handler can be called to any url.
Things to Know About Anonymous Handlers
The anonymous handlers should never be used for direct calls to handlers defined in other apps. Follow the practice that the apps should not be aware of each other.
An app can only have one response per URL, that is why anonymous handlers can't be combined with declared ones.
The
Html
property is not required, it may be blank if the calling app does not have any response.The anonymous handler response should be of type
Starcounter.Page
otherwise it won't be possible to merge with other responses.
When to Use Anonymous Handlers
Shared UI Sections
The most common case is the Launcher. The Launcher defines different UI sections and populates them with anonymous Self.GET
requests.
The model.Menu
contains merged responses from all handlers mapped to /sc/mapping/menu
. The mapping would look like this:
Read more about mapping here: Mixing apps.
UI View Composition with Layout Editor
Composition technology requires some extra HTML elements and JSON wrapping which are injected per partial using middleware. This means that partials which are created without a request won't be available for view composition.
An anonymous handler can be used instead of the custom partial handler definition.
Last updated