RazorDocs Search

Bridge

Type

TurboRequestExtensions

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

  • requestThe HttpRequest to check.

Returns

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

Type

RazorWireStreamBuilder

A fluent builder for creating Turbo Stream responses.

Method

Append

RazorWireStreamBuilder Append(string target, string templateHtml)

Queues an append action that inserts the provided HTML into the specified target element.

Parameters

  • targetThe target DOM selector or element identifier to which the HTML will be appended.
  • templateHtmlThe HTML fragment to append inside the target's template.

Returns

The same RazorWireStreamBuilder instance to allow fluent chaining.

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

  • targetThe DOM target selector or element identifier where the partial will be appended.
  • viewNameThe name of the partial view to render.
  • modelAn optional model to pass to the partial view.

Returns

The current RazorWireStreamBuilder instance for fluent chaining.

Method

Prepend

RazorWireStreamBuilder Prepend(string target, string templateHtml)

Queues a raw HTML prepend action targeting the specified DOM element.

Parameters

  • targetThe DOM target selector or identifier to receive the content.
  • templateHtmlThe HTML content to insert before the target element's existing content.

Returns

The builder instance for fluent chaining.

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

  • targetThe DOM selector or element identifier to receive the rendered partial.
  • viewNameThe name or path of the partial view to render.
  • modelThe 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 templateHtml)

Queues a raw HTML replace action targeting the specified DOM element.

Parameters

  • targetThe DOM element selector or identifier to target.
  • templateHtmlThe HTML content used to replace the target's contents.

Returns

The current RazorWireStreamBuilder instance.

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

  • targetThe DOM element selector or identifier to target for the replace action.
  • viewNameThe name of the partial view to render.
  • modelAn optional model passed to the partial view.

Returns

The same RazorWireStreamBuilder instance for fluent chaining.

Method

Update

RazorWireStreamBuilder Update(string target, string templateHtml)

Queues a raw HTML "update" turbo-stream action for the specified DOM target using the provided HTML template.

Parameters

  • targetThe DOM target selector or identifier to apply the update to.
  • templateHtmlThe HTML fragment to use as the action's template.

Returns

The same RazorWireStreamBuilder instance for fluent chaining.

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

  • targetThe DOM target selector or identifier to update.
  • viewNameThe name of the partial view to render.
  • modelAn 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

  • TThe ViewComponent type to render.

Parameters

  • targetThe DOM element selector or identifier to target for the append action.
  • argumentsOptional 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

  • targetThe DOM element selector or identifier to target.
  • componentNameThe name of the view component to render.
  • argumentsOptional 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

  • TThe view component type to render.

Parameters

  • targetThe DOM target selector or identifier to prepend the component into.
  • argumentsOptional 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

  • targetThe DOM element selector or identifier to target.
  • componentNameThe name of the view component to render and prepend.
  • argumentsOptional 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

  • targetThe DOM target selector or identifier to apply the replace action to.
  • argumentsOptional 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

  • targetThe DOM target selector or identifier to apply the replace action to.
  • componentNameThe name of the view component to render.
  • argumentsOptional 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

  • TThe view component type to render.

Parameters

  • targetThe DOM element selector or identifier that the turbo-stream will target.
  • argumentsOptional 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

  • targetThe DOM target selector or identifier to apply the update to.
  • componentNameThe name of the view component to render.
  • argumentsOptional arguments to pass to the view component.

Returns

The builder instance for fluent chaining.

Method

Remove

RazorWireStreamBuilder Remove(string target)

Queues a remove action targeting the specified DOM element.

Parameters

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

Returns

The current RazorWireStreamBuilder instance for fluent chaining.

Method

Build

string Build()

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

Returns

The concatenated Turbo Stream markup representing the queued raw HTML actions.

Exceptions

  • InvalidOperationExceptionThrown 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

  • viewContextThe view rendering context to use for each action.
  • cancellationTokenToken to observe for cancellation.

Returns

The concatenated HTML string produced by rendering each queued action.

Method

BuildResult

RazorWireStreamResult BuildResult()

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

Returns

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

Type

RawHtmlStreamAction

Method

RenderAsync

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

Renders the action as a turbo-stream HTML string.

Parameters

  • viewContextThe rendering context used when rendering the action.
  • cancellationTokenCancellation 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

RazorPartialRenderer

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

RazorWireStreamResult

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

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

Remarks

Generates and stores antiforgery tokens before sending any response data, sets the response Content-Type to "text/vnd.turbo-stream.html", and streams each action's rendered HTML to the response using UTF-8 encoding. Rendering of actions is performed asynchronously in parallel.

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

  • actionContextThe 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

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

  • viewContextThe view rendering context supplied to the action.
  • cancellationTokenCancellation token (ignored for raw HTML).

Returns

The stored HTML string.

Type

NullView

Method

RenderAsync

Task RenderAsync(ViewContext viewContext)

Performs no rendering and completes immediately.

Parameters

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

Returns

A completed Task representing the finished render operation.

Type

IRazorWireStreamAction

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

  • viewContextThe Razor view rendering context used to produce the HTML output.
  • cancellationTokenA token to observe while waiting for the task to complete.

Returns

The rendered HTML for this stream action.

Type

ViewComponentStreamHelper

Internal helper for rendering view components into Turbo Stream fragments.

Method

RenderComponentStreamAsync

Task<string> RenderComponentStreamAsync(ViewContext viewContext, string action, string target, dynamic componentIdentifier, object? arguments)

Renders a view component into a Turbo Stream XML fragment.

Parameters

  • viewContextThe current Razor view context used as the basis for rendering.
  • actionThe Turbo Stream action (e.g., "replace", "append").
  • targetThe DOM element identifier to update.
  • componentIdentifierThe view component to invoke; either a CLR Type or the component's string name.
  • argumentsOptional arguments to pass to the view component.

Returns

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

Type

ViewComponentStreamAction

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

  • viewContextThe current MVC view context used to execute and render the view component.
  • cancellationTokenA 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

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

  • viewContextThe current Razor view context used to execute and render the view component.
  • cancellationTokenA 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

RazorWireBridge

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

  • controllerThe controller used to produce the partial view result.
  • idThe identifier to assign to the turbo frame.
  • partialViewThe name of the inner partial view to render inside the frame.
  • modelAn 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

  • controllerThe controller instance from which to produce results.
  • idIdentifier for the turbo frame.
  • componentNameName of the view component to render inside the frame.
  • modelOptional 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

  • controllerThe 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

Method

RenderAsync

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

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

Parameters

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

Returns

A completed Task.

Type

TurboFrameViewModel

Data model used for rendering the Turbo Frame partial view.

Property

Id

string Id { get; set; }

Gets or sets the unique identifier for the Turbo Frame.

Property

PartialView

string? PartialView { get; set; }

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

Property

ViewComponent

string? ViewComponent { get; set; }

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

Property

Model

object? Model { get; set; }

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

Type

IRazorPartialRenderer

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

  • viewNameThe name or path of the partial view to render.
  • modelOptional model to pass to the view.
  • cancellationTokenA token to monitor for cancellation requests.

Returns

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

Type

PartialViewStreamAction

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

  • viewContextThe current view context used to locate services and render the partial view.
  • cancellationTokenA 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

  • InvalidOperationExceptionThrown if the partial view cannot be located.