AppSurface Search
API Reference

Bridge

Type

PartialViewStreamAction

Source

A Turbo Stream action that renders a partial view as its content.

Method

RenderAsync

Task<string> RenderAsync(ViewContext viewContext, CancellationToken cancellationToken = default)

Renders the configured partial view and wraps its output in a Turbo Stream element.

Parameters

  • viewContext
    The current view context used to locate services and render the partial view.
  • cancellationToken
    A token to observe while waiting for the task to complete.

Returns

The turbo-stream HTML string containing the rendered partial inside a <template> element.

Exceptions

  • InvalidOperationException
    Thrown if the partial view cannot be located.
Method

RenderPartialContentAsync

Task<string> RenderPartialContentAsync(ViewContext viewContext, string viewName, object? model, CancellationToken cancellationToken = default)

Renders a partial view body without adding an outer Turbo Stream element.

Parameters

  • viewContext
    The MVC context used to locate services and render the partial.
  • viewName
    The partial view name or path.
  • model
    The model passed to the partial.
  • cancellationToken
    The request cancellation token.

Returns

The trusted Razor-rendered partial body.

Exceptions

  • InvalidOperationException
    Thrown when the partial view cannot be located.
Type

ViewComponentStreamHelper

Source

Internal helper for rendering view components into Turbo Stream fragments.

Method

RenderComponentStreamAsync

Task<string> RenderComponentStreamAsync(ViewContext viewContext, string action, string target, object componentIdentifier, object? arguments, CancellationToken cancellationToken = default)

Renders a view component into a Turbo Stream XML fragment.

Parameters

  • viewContext
    The current Razor view context used as the basis for rendering.
  • action
    The Turbo Stream action (e.g., "replace", "append").
  • target
    The DOM element identifier to update.
  • componentIdentifier
    The view component to invoke; either a CLR Type or the component's string name.
  • arguments
    Optional arguments to pass to the view component.
  • cancellationToken
    The request cancellation token.

Returns

A Turbo Stream XML fragment whose `action` and `target` attributes are HTML-encoded and whose <template> contains the rendered component HTML.

Method

RenderComponentContentAsync

Task<string> RenderComponentContentAsync(ViewContext viewContext, object componentIdentifier, object? arguments, CancellationToken cancellationToken = default)

Renders a view component body without adding an outer Turbo Stream element.

Parameters

  • viewContext
    The current Razor view context used as the basis for rendering.
  • componentIdentifier
    The component type or name.
  • arguments
    Optional arguments passed to the component.
  • cancellationToken
    The request cancellation token.

Returns

The rendered component HTML.

Type

ViewComponentStreamAction

Source

A Turbo Stream action that renders a view component by its Type .

Method

RenderAsync

Task<string> RenderAsync(ViewContext viewContext, CancellationToken cancellationToken = default)

Renders the configured view component into a Turbo Stream fragment.

Parameters

  • viewContext
    The current MVC view context used to execute and render the view component.
  • cancellationToken
    A token to observe while deciding whether to proceed.

Returns

A string containing a <turbo-stream> element whose action and target attributes are HTML-encoded and whose <template> contains the component's rendered HTML.

Type

ViewComponentByNameStreamAction

Source

A Turbo Stream action that renders a view component by its name.

Method

RenderAsync

Task<string> RenderAsync(ViewContext viewContext, CancellationToken cancellationToken = default)

Render the configured view component (by name) into a Turbo Stream fragment.

Parameters

  • viewContext
    The current Razor view context used to execute and render the view component.
  • cancellationToken
    A token to observe while waiting for the task to complete.

Returns

A string containing a <turbo-stream> element whose action and target attributes are HTML-encoded and whose <template> contains the rendered component HTML.

Type

ISynchronousRazorWireStreamAction

Source

Represents a RazorWire stream action that can render without view or component services.

Remarks

RazorWireStreamBuilder.Build uses this internal contract for stream actions whose markup is already fully known. Actions that need Razor view rendering should implement only IRazorWireStreamAction so callers are directed to RazorWireStreamBuilder.RenderAsync(ViewContext, CancellationToken) or RazorWireStreamBuilder.BuildResult(int?) .

Method

Render

string Render()

Renders this action into a Turbo Stream fragment without using MVC rendering services.

Returns

The complete Turbo Stream fragment for the action.

Type

IRazorPartialRenderer

Source

Provides a mechanism to render Razor partial views to strings, specifically useful for background services and non-HTTP request contexts.

Method

RenderPartialToStringAsync

Task<string> RenderPartialToStringAsync(string viewName, object? model = null, CancellationToken cancellationToken = default)

Renders a partial view as an HTML string.

Parameters

  • viewName
    The name or path of the partial view to render.
  • model
    Optional model to pass to the view.
  • cancellationToken
    A token to monitor for cancellation requests.

Returns

A task that represents the asynchronous render operation. The task result contains the rendered HTML string.

Type

RazorWireStreamResult

Source

An IActionResult that renders and streams Turbo Stream actions to the response.

Method

ExecuteResultAsync

Task ExecuteResultAsync(ActionContext context)

Streams rendered Turbo Stream HTML for the configured actions to the HTTP response.

Parameters

  • context
    The current action context used to build the view context and access the HTTP response.

Remarks

A dialog-containing result validates request correlation and sequentially renders the complete action snapshot before generating antiforgery tokens or setting response headers, so a later render failure cannot leave an earlier action partially applied. It then writes the buffered markup and echoes the validated request UUID in X-RazorWire-Request . A correlated page-only result attaches metadata to package-authored target actions and echoes that request UUID while retaining the existing ordered streaming renderer. An uncorrelated page-only result remains compatible with callers that do not send RazorWire correlation headers.

Method

CreateViewContext

ViewContext CreateViewContext(ActionContext actionContext)

Creates a ViewContext configured for rendering the stream actions, optionally inheriting ViewData and TempData from the associated controller.

Parameters

  • actionContext
    The current ActionContext used to build the ViewContext.

Returns

A ViewContext configured with a NullView , the prepared ViewData, TempData (the controller's if available or obtained from ITempDataDictionaryFactory), TextWriter.Null, and default HtmlHelperOptions.

Type

RawHtmlStreamAction

Source
Method

RenderAsync

Task<string> RenderAsync(ViewContext viewContext, CancellationToken cancellationToken = default)

Produces the stored raw HTML as the rendered output for the given view context.

Parameters

  • viewContext
    The view rendering context supplied to the action.
  • cancellationToken
    Cancellation token (ignored for raw HTML).

Returns

The stored HTML string.

Type

NullView

Source
Method

RenderAsync

Task RenderAsync(ViewContext viewContext)

Performs no rendering and completes immediately.

Parameters

  • viewContext
    The rendering context provided by the framework; this implementation ignores it.

Returns

A completed Task representing the finished render operation.

Type

RazorWireDialogPayload

Source

Describes the immutable body selection captured by one dialog command.

Method

ForMessage

RazorWireDialogPayload ForMessage(string title, string? message)

Creates a validated plain-text dialog payload.

Method

ForPartial

RazorWireDialogPayload ForPartial(string title, string viewName, object? model)

Creates a validated partial-view dialog payload.

Method

ForComponent

RazorWireDialogPayload ForComponent(string title, Type componentType, object? arguments)

Creates a validated typed-component dialog payload.

Method

ForNamedComponent

RazorWireDialogPayload ForNamedComponent(string title, string componentName, object? arguments)

Creates a validated named-component dialog payload.

Type

RazorWireDialogStreamAction

Source

Renders the single normalized dialog command captured by a builder snapshot.

Method

Open

RazorWireDialogStreamAction Open(RazorWireDialogPayload payload)

Creates the final open command for the selected payload.

Parameters

  • payload
    The immutable body selection captured by the builder.

Returns

The open command action.

Method

Close

RazorWireDialogStreamAction Close()

Creates the final close command.

Returns

The close command action.

Method

RenderAsync

Task<string> RenderAsync(ViewContext viewContext, CancellationToken cancellationToken = default)

Rejects rendering without validated request metadata.

Parameters

  • viewContext
    The MVC view context.
  • cancellationToken
    The request cancellation token.

Returns

This method never returns markup.

Type

RazorWireRequestMetadata

Source

Describes the validated request correlation values echoed on package-authored stream elements.

Method

Read

RazorWireRequestMetadata? Read(HttpRequest request, bool required)

Reads and validates correlation values from a request.

Parameters

  • request
    The request whose correlation headers are inspected.
  • required
    Whether request and order values are required even when all headers are absent.

Returns

The validated metadata, or null when no correlation headers were supplied and metadata is optional.

Exceptions

  • InvalidOperationException
    Thrown when required metadata is missing or any supplied header is duplicated, oversized, or malformed.
Method

ToHtmlAttributes

string ToHtmlAttributes(RazorWireDialogPhase phase)

Creates encoded HTML attributes for a stream element using this request metadata and the action's position.

Parameters

  • phase
    The resolved dialog phase for the action.

Returns

A space-prefixed string of encoded data-rw-* attributes.

Type

IRazorWireTargetedStreamAction

Source

Renders package-authored target actions with request correlation metadata.

Method

RenderCorrelatedAsync

Task<string> RenderCorrelatedAsync(ViewContext viewContext, RazorWireRequestMetadata metadata, RazorWireDialogPhase phase, CancellationToken cancellationToken = default)

Renders this action with validated request correlation metadata.

Type

IRazorWireDialogCommandStreamAction

Source

Marks the single final dialog command in a builder snapshot.

Method

RenderCorrelatedAsync

Task<string> RenderCorrelatedAsync(ViewContext viewContext, RazorWireRequestMetadata metadata, CancellationToken cancellationToken = default)

Renders this command with validated request correlation metadata.

Property

Command

RazorWireDialogCommand Command { get; } Source

Gets whether the command opens or closes the pending dialog.

Type

RazorWireStreamRendering

Source

Provides shared action-position and rendering logic for builder and result paths.

Method

FindDialogCommandIndex

int FindDialogCommandIndex(IReadOnlyList<IRazorWireStreamAction> actions)

Finds the final dialog command's position in a snapshot.

Parameters

  • actions
    The immutable action snapshot.

Returns

The command index, or -1 when the response has no dialog command.

Method

GetPhase

RazorWireDialogPhase GetPhase(int actionIndex, int dialogIndex, RazorWireDialogCommand? command)

Resolves the phase for a built-in target action from its position relative to the final command.

Parameters

  • actionIndex
    The action's index in the snapshot.
  • dialogIndex
    The dialog command index, or -1 for page-only output.
  • command
    The final dialog command when one exists.

Returns

The phase serialized for the action.

Method

RenderActionAsync

Task<string> RenderActionAsync(IRazorWireStreamAction action, ViewContext viewContext, RazorWireRequestMetadata? metadata, RazorWireDialogPhase phase, CancellationToken cancellationToken)

Renders one action, adding metadata only for typed built-in target or dialog actions.

Parameters

  • action
    The action to render.
  • viewContext
    The MVC rendering context.
  • metadata
    Validated request metadata, or null for legacy uncorrelated output.
  • phase
    The phase to attach to a targeted action.
  • cancellationToken
    The request cancellation token.

Returns

The rendered stream markup.

Type

RazorWireStreamMarkup

Source

Encodes and wraps built-in target actions with an optional, already validated correlation value.

Method

RenderTargeted

string RenderTargeted(string action, string target, string? content, bool hasTemplate, RazorWireRequestMetadata? metadata = null, RazorWireDialogPhase phase = RazorWireDialogPhase.Origin)

Renders one package-authored targeted Turbo Stream element.

Parameters

  • action
    The Turbo action name.
  • target
    The target selector or identifier.
  • content
    The template body, if the action uses a template.
  • hasTemplate
    Whether the action should include a template element.
  • metadata
    Validated request metadata, or null for uncorrelated output.
  • phase
    The action's dialog phase when metadata is present.

Returns

The encoded Turbo Stream element.

Type

RazorWireStreamBuilder

Source

A fluent builder for creating Turbo Stream responses.

Method

Append

RazorWireStreamBuilder Append(string target, string? content)

Queues an append action that inserts HTML-encoded text into the specified target element.

Parameters

  • target
    The target DOM selector or element identifier to which the encoded text will be appended.
  • content
    Plain-text content to append inside the target's template; null renders as empty text.

Returns

The same RazorWireStreamBuilder instance to allow fluent chaining.

Remarks

This method treats content as plain text and HTML-encodes it before writing it to the stream template. Use AppendHtml(string,string?) only when the caller already owns a trusted HTML fragment and has encoded any user-supplied values inside it.

Method

AppendHtml

RazorWireStreamBuilder AppendHtml(string target, string? trustedHtml)

Queues an append action that inserts a trusted HTML fragment into the specified target element without encoding or sanitizing it.

Parameters

  • target
    The target DOM selector or element identifier to which the trusted HTML will be appended.
  • trustedHtml
    Trusted HTML to append inside the target's template; null renders as an empty fragment.

Returns

The same RazorWireStreamBuilder instance to allow fluent chaining.

Remarks

This is the raw-markup escape hatch for server-authored fragments. RazorWire does not encode or sanitize trustedHtml ; callers must ensure the fragment is trusted and that any user-supplied values have already been HTML-encoded. Prefer Append(string,string?) for text and AppendPartial(string,string,object?) or AppendComponent{T}(string,object?) for Razor-rendered markup.

Method

AppendPartial

RazorWireStreamBuilder AppendPartial(string target, string viewName, object? model = null)

Queues an action to append the rendered partial view to the specified DOM target.

Parameters

  • target
    The DOM target selector or element identifier where the partial will be appended.
  • viewName
    The name of the partial view to render.
  • model
    An optional model to pass to the partial view.

Returns

The current RazorWireStreamBuilder instance for fluent chaining.

Method

Prepend

RazorWireStreamBuilder Prepend(string target, string? content)

Queues a prepend action that inserts HTML-encoded text into the specified target element.

Parameters

  • target
    The DOM target selector or identifier to receive the content.
  • content
    Plain-text content to insert before the target element's existing content; null renders as empty text.

Returns

The builder instance for fluent chaining.

Remarks

RazorWire HTML-encodes content before placing it in the stream template. Use PrependHtml(string,string?) only for trusted, already-safe HTML fragments.

Method

PrependHtml

RazorWireStreamBuilder PrependHtml(string target, string? trustedHtml)

Queues a prepend action that inserts a trusted HTML fragment without encoding or sanitizing it.

Parameters

  • target
    The DOM target selector or identifier to receive the trusted HTML.
  • trustedHtml
    Trusted HTML content to insert before the target element's existing content; null renders as an empty fragment.

Returns

The builder instance for fluent chaining.

Remarks

RazorWire writes trustedHtml directly into the stream template. Use this only for server-authored trusted markup; encode user values before composing the fragment. Prefer Prepend(string,string?) for text and partial or component helpers for Razor-rendered markup.

Method

PrependPartial

RazorWireStreamBuilder PrependPartial(string target, string viewName, object? model = null)

Queues an action to prepend the rendered partial view into the specified DOM target.

Parameters

  • target
    The DOM selector or element identifier to receive the rendered partial.
  • viewName
    The name or path of the partial view to render.
  • model
    The model to pass to the partial view, or null if none.

Returns

The current RazorWireStreamBuilder instance for fluent chaining.

Method

Replace

RazorWireStreamBuilder Replace(string target, string? content)

Queues a replace action that inserts HTML-encoded text into the specified target element.

Parameters

  • target
    The DOM element selector or identifier to target.
  • content
    Plain-text content used to replace the target's contents; null renders as empty text.

Returns

The current RazorWireStreamBuilder instance.

Remarks

RazorWire HTML-encodes content before placing it in the stream template. Use ReplaceHtml(string,string?) only for trusted HTML fragments.

Method

ReplaceHtml

RazorWireStreamBuilder ReplaceHtml(string target, string? trustedHtml)

Queues a replace action that inserts a trusted HTML fragment without encoding or sanitizing it.

Parameters

  • target
    The DOM element selector or identifier to target.
  • trustedHtml
    Trusted HTML content used to replace the target's contents; null renders as an empty fragment.

Returns

The current RazorWireStreamBuilder instance.

Remarks

RazorWire writes trustedHtml directly into the stream template. Use this only for server-authored trusted markup; encode user values before composing the fragment. Prefer Replace(string,string?) for text and partial or component helpers for Razor-rendered markup.

Method

ReplacePartial

RazorWireStreamBuilder ReplacePartial(string target, string viewName, object? model = null)

Queues a partial view to replace the contents of the specified DOM target with the rendered partial.

Parameters

  • target
    The DOM element selector or identifier to target for the replace action.
  • viewName
    The name of the partial view to render.
  • model
    An optional model passed to the partial view.

Returns

The same RazorWireStreamBuilder instance for fluent chaining.

Method

Update

RazorWireStreamBuilder Update(string target, string? content)

Queues an update action that inserts HTML-encoded text into the specified target element.

Parameters

  • target
    The DOM target selector or identifier to apply the update to.
  • content
    Plain-text content to use as the action's template; null renders as empty text.

Returns

The same RazorWireStreamBuilder instance for fluent chaining.

Remarks

RazorWire HTML-encodes content before placing it in the stream template. Use UpdateHtml(string,string?) only for trusted HTML fragments.

Method

UpdateHtml

RazorWireStreamBuilder UpdateHtml(string target, string? trustedHtml)

Queues an update action that inserts a trusted HTML fragment without encoding or sanitizing it.

Parameters

  • target
    The DOM target selector or identifier to apply the update to.
  • trustedHtml
    Trusted HTML fragment to use as the action's template; null renders as an empty fragment.

Returns

The same RazorWireStreamBuilder instance for fluent chaining.

Remarks

RazorWire writes trustedHtml directly into the stream template. Use this only for server-authored trusted markup; encode user values before composing the fragment. Prefer Update(string,string?) for text and partial or component helpers for Razor-rendered markup.

Method

UpdatePartial

RazorWireStreamBuilder UpdatePartial(string target, string viewName, object? model = null)

Queues an "update" turbo-stream action that renders the specified partial view into the given target element.

Parameters

  • target
    The DOM target selector or identifier to update.
  • viewName
    The name of the partial view to render.
  • model
    An optional model to pass to the partial view.

Returns

The builder instance for further chaining.

Method

AppendComponent

2 overloads
RazorWireStreamBuilder AppendComponent<T>(string target, object? arguments = null)

Queues an append action that will render the specified view component into the given DOM target.

Type parameters

  • T
    The ViewComponent type to render.

Parameters

  • target
    The DOM element selector or identifier to target for the append action.
  • arguments
    Optional arguments passed to the view component when rendering.

Returns

The same RazorWireStreamBuilder instance for fluent chaining.

RazorWireStreamBuilder AppendComponent(string target, string componentName, object? arguments = null)

Queues an "append" turbo-stream action that will render the specified view component (by name) into the given target element.

Parameters

  • target
    The DOM element selector or identifier to target.
  • componentName
    The name of the view component to render.
  • arguments
    Optional arguments to pass to the view component.

Returns

The current RazorWireStreamBuilder instance for method chaining.

Method

PrependComponent

2 overloads
RazorWireStreamBuilder PrependComponent<T>(string target, object? arguments = null)

Queues a view component render action that will prepend the component's output into the specified DOM target.

Type parameters

  • T
    The view component type to render.

Parameters

  • target
    The DOM target selector or identifier to prepend the component into.
  • arguments
    Optional arguments passed to the view component.

Returns

The same RazorWireStreamBuilder instance for fluent chaining.

RazorWireStreamBuilder PrependComponent(string target, string componentName, object? arguments = null)

Queues a view component prepend action targeting a DOM element by name.

Parameters

  • target
    The DOM element selector or identifier to target.
  • componentName
    The name of the view component to render and prepend.
  • arguments
    Optional arguments to pass to the view component.

Returns

The current builder instance for fluent chaining.

Method

ReplaceComponent

2 overloads
RazorWireStreamBuilder ReplaceComponent<T>(string target, object? arguments = null)

Queues a view component replace action targeting the specified DOM element.

Parameters

  • target
    The DOM target selector or identifier to apply the replace action to.
  • arguments
    Optional arguments to pass to the view component.

Returns

The builder instance for fluent chaining.

RazorWireStreamBuilder ReplaceComponent(string target, string componentName, object? arguments = null)

Queue a replace action that renders the specified view component by name into the given DOM target.

Parameters

  • target
    The DOM target selector or identifier to apply the replace action to.
  • componentName
    The name of the view component to render.
  • arguments
    Optional arguments to pass to the view component.

Returns

The same RazorWireStreamBuilder instance for fluent chaining.

Method

UpdateComponent

2 overloads
RazorWireStreamBuilder UpdateComponent<T>(string target, object? arguments = null)

Queues an "update" turbo-stream action that renders the specified view component type into the given target element.

Type parameters

  • T
    The view component type to render.

Parameters

  • target
    The DOM element selector or identifier that the turbo-stream will target.
  • arguments
    Optional arguments to pass to the view component.

Returns

The same RazorWireStreamBuilder instance for fluent chaining.

RazorWireStreamBuilder UpdateComponent(string target, string componentName, object? arguments = null)

Queues a view component update action for a named view component.

Parameters

  • target
    The DOM target selector or identifier to apply the update to.
  • componentName
    The name of the view component to render.
  • arguments
    Optional arguments to pass to the view component.

Returns

The builder instance for fluent chaining.

Method

OpenDialog

RazorWireStreamBuilder OpenDialog(string title, string? message)

Queues a dialog command that opens a titled dialog containing an HTML-encoded plain-text message.

Parameters

  • title
    Nonblank plain-text dialog title; RazorWire encodes it as an HTML attribute.
  • message
    Optional plain-text body; RazorWire HTML-encodes it, and null means an empty body.

Returns

This builder for fluent chaining.

Exceptions

  • ArgumentException
    Thrown when title is null, empty, or whitespace.
  • InvalidOperationException
    Thrown when another dialog open payload is already pending.

Remarks

A builder can hold only one pending dialog payload. Calling another OpenDialog* method while HasActiveDialog is true throws immediately; use a ReplaceDialog* method to explicitly overwrite the pending title and body. A null message produces an empty body. The dialog command occupies the position of the first dialog operation, so page actions retain their order around that position. The command requires request correlation and therefore can be emitted with BuildResult(int?) or rendered with RenderAsync(Microsoft.AspNetCore.Mvc.Rendering.ViewContext,CancellationToken) ; it cannot be emitted with Build .

Method

OpenDialogPartial

RazorWireStreamBuilder OpenDialogPartial(string title, string viewName, object? model = null)

Queues a dialog command that opens a titled dialog containing a rendered partial view.

Parameters

  • title
    Nonblank plain-text dialog title; RazorWire encodes it as an HTML attribute.
  • viewName
    The MVC partial view name or path to render as the dialog body.
  • model
    Optional model passed to the partial view.

Returns

This builder for fluent chaining.

Exceptions

  • ArgumentException
    Thrown when title or viewName is null, empty, or whitespace.
  • InvalidOperationException
    Thrown when another dialog open payload is already pending.

Remarks

Only the final buffered dialog payload is rendered. A later ReplaceDialog* call overwrites this partial without invoking its view. The partial uses the existing trusted Razor markup boundary. The command requires request correlation, so use BuildResult(int?) or RenderAsync(Microsoft.AspNetCore.Mvc.Rendering.ViewContext,CancellationToken) .

Method

OpenDialogComponent

2 overloads
RazorWireStreamBuilder OpenDialogComponent<T>(string title, object? arguments = null)

Queues a dialog command that opens a titled dialog containing a rendered view component selected by type.

Type parameters

  • T
    The ViewComponent type to render.

Parameters

  • title
    Nonblank plain-text dialog title; RazorWire encodes it as an HTML attribute.
  • arguments
    Optional arguments passed to the view component.

Returns

This builder for fluent chaining.

Exceptions

  • ArgumentException
    Thrown when title is null, empty, or whitespace.
  • InvalidOperationException
    Thrown when another dialog open payload is already pending.

Remarks

Only the final buffered dialog payload is rendered. A later ReplaceDialog* call overwrites this component without invoking it. The component uses the existing trusted Razor markup boundary. The command requires request correlation, so use BuildResult(int?) or RenderAsync(Microsoft.AspNetCore.Mvc.Rendering.ViewContext,CancellationToken) .

RazorWireStreamBuilder OpenDialogComponent(string title, string componentName, object? arguments = null)

Queues a dialog command that opens a titled dialog containing a rendered view component selected by name.

Parameters

  • title
    Nonblank plain-text dialog title; RazorWire encodes it as an HTML attribute.
  • componentName
    The MVC view component name to render as the dialog body.
  • arguments
    Optional arguments passed to the view component.

Returns

This builder for fluent chaining.

Exceptions

  • ArgumentException
    Thrown when title or componentName is null, empty, or whitespace.
  • InvalidOperationException
    Thrown when another dialog open payload is already pending.

Remarks

Only the final buffered dialog payload is rendered. A later ReplaceDialog* call overwrites this component without invoking it. The component uses the existing trusted Razor markup boundary. The command requires request correlation, so use BuildResult(int?) or RenderAsync(Microsoft.AspNetCore.Mvc.Rendering.ViewContext,CancellationToken) .

Method

ReplaceDialog

RazorWireStreamBuilder ReplaceDialog(string title, string? message)

Replaces the pending dialog title and body with an HTML-encoded plain-text message.

Parameters

  • title
    Nonblank plain-text dialog title; RazorWire encodes it as an HTML attribute.
  • message
    Optional plain-text body; RazorWire HTML-encodes it, and null means an empty body.

Returns

This builder for fluent chaining.

Exceptions

  • ArgumentException
    Thrown when title is null, empty, or whitespace.
  • InvalidOperationException
    Thrown when no dialog open payload is pending.

Remarks

Replacement changes the single unsent dialog slot and creates no intermediate browser command. It requires a pending open payload, as reported by HasActiveDialog . A null message produces an empty body.

Method

ReplaceDialogPartial

RazorWireStreamBuilder ReplaceDialogPartial(string title, string viewName, object? model = null)

Replaces the pending dialog title and body with a rendered partial view.

Parameters

  • title
    Nonblank plain-text dialog title; RazorWire encodes it as an HTML attribute.
  • viewName
    The MVC partial view name or path to render as the dialog body.
  • model
    Optional model passed to the partial view.

Returns

This builder for fluent chaining.

Exceptions

  • ArgumentException
    Thrown when title or viewName is null, empty, or whitespace.
  • InvalidOperationException
    Thrown when no dialog open payload is pending.

Remarks

Replacement changes the single unsent dialog slot and creates no intermediate browser command. It requires a pending open payload, as reported by HasActiveDialog . Only the final partial is rendered.

Method

ReplaceDialogComponent

2 overloads
RazorWireStreamBuilder ReplaceDialogComponent<T>(string title, object? arguments = null)

Replaces the pending dialog title and body with a rendered view component selected by type.

Type parameters

  • T
    The ViewComponent type to render.

Parameters

  • title
    Nonblank plain-text dialog title; RazorWire encodes it as an HTML attribute.
  • arguments
    Optional arguments passed to the view component.

Returns

This builder for fluent chaining.

Exceptions

  • ArgumentException
    Thrown when title is null, empty, or whitespace.
  • InvalidOperationException
    Thrown when no dialog open payload is pending.

Remarks

Replacement changes the single unsent dialog slot and creates no intermediate browser command. It requires a pending open payload, as reported by HasActiveDialog . Only the final component is rendered.

RazorWireStreamBuilder ReplaceDialogComponent(string title, string componentName, object? arguments = null)

Replaces the pending dialog title and body with a rendered view component selected by name.

Parameters

  • title
    Nonblank plain-text dialog title; RazorWire encodes it as an HTML attribute.
  • componentName
    The MVC view component name to render as the dialog body.
  • arguments
    Optional arguments passed to the view component.

Returns

This builder for fluent chaining.

Exceptions

  • ArgumentException
    Thrown when title or componentName is null, empty, or whitespace.
  • InvalidOperationException
    Thrown when no dialog open payload is pending.

Remarks

Replacement changes the single unsent dialog slot and creates no intermediate browser command. It requires a pending open payload, as reported by HasActiveDialog . Only the final component is rendered.

Method

CloseDialog

RazorWireStreamBuilder CloseDialog()

Queues an explicit close command in the builder's single dialog slot.

Returns

This builder for fluent chaining.

Remarks

Closing clears any pending open payload, so HasActiveDialog becomes false. Repeated calls are idempotent. A later OpenDialog* call changes the same slot to open; a close command requires BuildResult(int?) or request-aware RenderAsync(Microsoft.AspNetCore.Mvc.Rendering.ViewContext,CancellationToken) and cannot be emitted by Build .

Method

Remove

RazorWireStreamBuilder Remove(string target)

Queues a remove action targeting the specified DOM element.

Parameters

  • target
    The DOM target selector or identifier whose element will be removed.

Returns

The current RazorWireStreamBuilder instance for fluent chaining.

Method

Visit

2 overloads
RazorWireStreamBuilder Visit(string url)

Queues a one-shot Turbo Drive visit stream command that advances browser history.

Parameters

  • url
    The relative or same-origin URL that the browser should visit.

Returns

The current RazorWireStreamBuilder instance for fluent chaining.

Exceptions

  • ArgumentException
    Thrown when url is null, empty, whitespace, or contains an ASCII control character.

Remarks

RazorWire emits this command as a rw-visit Turbo Stream action with a visit-action value of advance . The browser runtime validates that the resolved URL stays on the current origin before calling Turbo. Visit commands are not idempotent state snapshots, so publish them only to live subscribers and never to retained replay channels.

RazorWireStreamBuilder Visit(string url, RazorWireVisitAction action)

Queues a one-shot Turbo Drive visit stream command.

Parameters

  • url
    The relative or same-origin URL that the browser should visit.
  • action
    The Turbo Drive history action to apply.

Returns

The current RazorWireStreamBuilder instance for fluent chaining.

Exceptions

  • ArgumentException
    Thrown when url is null, empty, whitespace, or contains an ASCII control character.
  • ArgumentOutOfRangeException
    Thrown when action is not a supported RazorWireVisitAction value.

Remarks

The generated stream contains no target or template ; it is a command for the RazorWire browser runtime. Server-side validation rejects only input that cannot safely be serialized. Origin checks happen in the browser because relative URLs resolve against the current document location. Do not use this method for fallback content or replayable state; render a normal link or retained state stream for those cases.

Method

FormError

RazorWireStreamBuilder FormError(string target, string title, string message)

Queues a form-local failure summary for an enhanced RazorWire form.

Parameters

  • target
    The Turbo target id whose element should receive the generated failure block.
  • title
    Plain-text failure title. RazorWire HTML-encodes this value.
  • message
    Plain-text failure message. RazorWire HTML-encodes this value.

Returns

The current RazorWireStreamBuilder instance for fluent chaining.

Remarks

The target value is emitted as Turbo's target attribute, so it should name the DOM element that Turbo will update, usually a form-local error container. Calling this method marks the stream as a handled form response; BuildResult(int?) will emit Forms.RazorWireFormHeaders.FormHandled so the browser runtime does not add a second fallback block for the same failed submission.

Method

FormValidationErrors

RazorWireStreamBuilder FormValidationErrors(string target, ModelStateDictionary modelState, string title = "Please fix the highlighted fields.", int maxErrors = 10, string message = "We could not submit this form. Check your input and try again.")

Queues a form-local validation summary from an MVC ModelStateDictionary .

Parameters

  • target
    The Turbo target id whose element should receive the generated validation block.
  • modelState
    The MVC model state to render into a validation summary.
  • title
    Plain-text summary title. RazorWire HTML-encodes this value.
  • maxErrors
    Maximum number of individual validation errors to show before an overflow line is added; values less than zero are treated as zero.
  • message
    Plain-text fallback message used when the model state contains no displayable errors.

Returns

The current RazorWireStreamBuilder instance for fluent chaining.

Remarks

The target value is emitted as Turbo's target attribute, so it should name the DOM element that Turbo will update. Calling this method marks the stream as a handled form response; BuildResult(int?) will emit Forms.RazorWireFormHeaders.FormHandled so the browser runtime does not render its default fallback UI. maxErrors is clamped to zero or greater. RazorWire orders collected errors by error.Key using StringComparer.Ordinal , then renders only the first maxErrors errors and adds an overflow line when more errors were hidden. For errors that share the same field key, original model-state insertion order is preserved. When the model state has no displayable errors, the provided message is rendered as the fallback copy.

Method

Build

string Build()

Builds a single concatenated Turbo Stream markup string from the queued synchronous actions.

Returns

The concatenated Turbo Stream markup representing the queued synchronous actions.

Exceptions

  • InvalidOperationException
    Thrown if the builder contains actions that require asynchronous rendering (such as partial views or view components); use RenderAsync(viewContext) or BuildResult() instead.
Method

RenderAsync

Task<string> RenderAsync(Microsoft.AspNetCore.Mvc.Rendering.ViewContext viewContext, CancellationToken cancellationToken = default)

Renders all queued stream actions using the provided ViewContext and concatenates their rendered HTML into a single string.

Parameters

  • viewContext
    The view rendering context to use for each action.
  • cancellationToken
    Token to observe for cancellation.

Returns

The concatenated HTML string produced by rendering each queued action.

Remarks

Snapshots the dialog slot before awaiting renderers and validates request correlation when a dialog is present. After successful rendering, echoes a correlated request UUID in the response's X-RazorWire-Request header when the response has not started, so handled validation can be associated with its submission. Once response headers are read-only, the header is left unchanged. Callers own the response content type, status, and handled-form header; prefer BuildResult(int?) when returning a controller response. See Docs/dialog-responses.md for the complete presentation contract.

Method

BuildResult

RazorWireStreamResult BuildResult(int? statusCode = null)

Creates a RazorWireStreamResult containing the builder's queued stream actions and associated controller.

Parameters

  • statusCode
    Optional HTTP status code to apply to the response, commonly 422 for handled validation failures.

Returns

A RazorWireStreamResult initialized with a copy of the queued actions and the builder's controller.

Remarks

If FormError(string,string,string) or FormValidationErrors(string,ModelStateDictionary,string,int,string) was queued, the result also emits the Forms.RazorWireFormHeaders.FormHandled response header. That header is the runtime contract that prevents the package default failed-form fallback from rendering on top of server-authored UI.

Property

HasActiveDialog

bool HasActiveDialog { get; } Source

Gets whether this builder currently has a pending dialog open payload.

Remarks

This reports only the builder's response buffer, not whether a browser currently displays a dialog. It is true after an open or replacement and false initially or after CloseDialog .

Type

TemplateStreamAction

Source
Method

Render

string Render()

Renders the action as a turbo-stream HTML string.

Returns

The turbo-stream element for the action and target; for action "remove" the element has no <template>, otherwise its <template> contains the action's HTML.

Method

RenderAsync

Task<string> RenderAsync(Microsoft.AspNetCore.Mvc.Rendering.ViewContext viewContext, CancellationToken cancellationToken = default)

Renders the action as a turbo-stream HTML string.

Parameters

  • viewContext
    The rendering context used when rendering the action.
  • cancellationToken
    Cancellation token (ignored for raw HTML).

Returns

The turbo-stream element for the action and target; for action "remove" the element has no <template>, otherwise its <template> contains the action's HTML.

Type

IRazorWireStreamAction

Source

Represents an action to be performed in a RazorWire stream (e.g., append, replace).

Method

RenderAsync

Task<string> RenderAsync(ViewContext viewContext, CancellationToken cancellationToken = default)

Renders the stream action to an HTML string using the provided view rendering context.

Parameters

  • viewContext
    The Razor view rendering context used to produce the HTML output.
  • cancellationToken
    A token to observe while waiting for the task to complete.

Returns

The rendered HTML for this stream action.

Type

RazorPartialRenderer

Source

Implements IRazorPartialRenderer using the Razor view engine.

Method

RenderPartialToStringAsync

Task<string> RenderPartialToStringAsync(string viewName, object? model = null, CancellationToken cancellationToken = default)

Remarks

Because this method executes outside of an HTTP request context, it uses a blank ActionContext (with empty RouteData and ActionDescriptor ). As a result, the IRazorViewEngine may not be able to locate views that are scoped to a specific controller (e.g., Views/ControllerName/ViewName.cshtml ) unless the full path is provided (e.g., ~/Views/Reactivity/_MyPartial.cshtml ). Shared views (e.g., Views/Shared/_MyPartial.cshtml ) are generally resolvable by name.

Type

TurboRequestExtensions

Source

Provides extension methods for HttpRequest to detect Turbo requests.

Method

IsTurboRequest

bool IsTurboRequest(this HttpRequest request)

Determines whether the request's Accept header signals a Turbo Stream response.

Parameters

  • request
    The HttpRequest to check.

Returns

true if the Accept header contains "text/vnd.turbo-stream.html", otherwise false .

Type

RazorWireBridge

Source

Provides static methods for creating Turbo Frame results and RazorWire stream builders.

Method

Frame

PartialViewResult Frame(Controller controller, string id, string partialView, object? model = null)

Creates a partial result that renders a turbo frame containing the specified inner partial view and model.

Parameters

  • controller
    The controller used to produce the partial view result.
  • id
    The identifier to assign to the turbo frame.
  • partialView
    The name of the inner partial view to render inside the frame.
  • model
    An optional model to pass to the inner partial view.

Returns

A PartialViewResult that renders the RazorWire/_TurboFrame partial populated with the specified id, partial view, and model.

Remarks

Also exposes the frame identifier by setting controller.ViewData["TurboFrameId"] .

Method

FrameComponent

PartialViewResult FrameComponent(Controller controller, string id, string componentName, object? model = null)

Creates a partial result that renders a Turbo Frame containing the specified view component. The frame identifier is exposed via Controller.ViewData["TurboFrameId"] .

Parameters

  • controller
    The controller instance from which to produce results.
  • id
    Identifier for the turbo frame.
  • componentName
    Name of the view component to render inside the frame.
  • model
    Optional model to pass to the view component.

Returns

A PartialViewResult that renders the RazorWire/_TurboFrame partial with a TurboFrameViewModel .

Method

CreateStream

RazorWireStreamBuilder CreateStream()

Creates a new RazorWireStreamBuilder for fluidly configuring and producing Turbo Stream actions.

Returns

A new RazorWireStreamBuilder instance ready to configure stream updates.

Method

CreateViewContext

Microsoft.AspNetCore.Mvc.Rendering.ViewContext CreateViewContext(this Controller controller)

Creates a Microsoft.AspNetCore.Mvc.Rendering.ViewContext configured to render outside of a regular view using the controller's context and data.

Parameters

  • controller
    The controller whose context and data are used as the basis for the new Microsoft.AspNetCore.Mvc.Rendering.ViewContext .

Returns

A Microsoft.AspNetCore.Mvc.Rendering.ViewContext configured with the controller's data and a no-op view.

Type

NullView

Source
Method

RenderAsync

Task RenderAsync(Microsoft.AspNetCore.Mvc.Rendering.ViewContext viewContext)

A no-op view that does not render any content.

Parameters

  • viewContext
    The view context provided for rendering; this implementation ignores it.

Returns

A completed Task .

Type

TurboFrameViewModel

Source

Data model used for rendering the Turbo Frame partial view.

Property

Id

string Id { get; set; } Source

Gets or sets the unique identifier for the Turbo Frame.

Property

PartialView

string? PartialView { get; set; } Source

Gets or sets the name of the partial view to render inside the frame, if any.

Property

ViewComponent

string? ViewComponent { get; set; } Source

Gets or sets the name of the view component to render inside the frame, if any.

Property

Model

object? Model { get; set; } Source

Gets or sets the optional model to pass to the partial view or view component.

Enum

RazorWireVisitAction

Source

Describes how Turbo Drive should apply a RazorWire visit stream command to browser history.

Remarks

Visit stream commands are one-shot navigation messages. Publish them only to live stream subscribers; do not retain or replay them through a RazorWire stream hub replay buffer. Use normal links, redirects, or retained state streams when late subscribers or JavaScript-disabled clients need a fallback.

Enum

RazorWireDialogBodyKind

Source

Identifies how the selected dialog body is rendered.

Enum

RazorWireDialogPhase

Source

Identifies which dialog flow a package-authored target action belongs to in one response.

Enum

RazorWireDialogCommand

Source

Identifies the final dialog command represented by a response.