RazorDocs Search
API Reference

Bridge

Type

RazorPartialRenderer

Source

Implements IRazorPartialRenderer using the Razor view engine.

Method

RenderPartialToStringAsync

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

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

PartialViewStreamAction

Source

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

Method

RenderAsync

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

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.
Type

TurboRequestExtensions

Source

Provides extension methods for HttpRequest to detect Turbo requests.

Method

IsTurboRequest

bool IsTurboRequest(this HttpRequest request) Source

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

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) Source

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) Source

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() Source

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) Source

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

Source
Method

RenderAsync

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

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

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.

Type

ViewComponentStreamHelper

Source

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) Source

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

Source

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

Method

RenderAsync

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

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

Source

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

Method

RenderAsync

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

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

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) Source

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

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) Source

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

RazorWireStreamBuilder

Source

A fluent builder for creating Turbo Stream responses.

Method

Append

RazorWireStreamBuilder Append(string target, string templateHtml) Source

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) Source

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) Source

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) Source

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) Source

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) Source

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) Source

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) Source

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) Source

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) Source

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) Source

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) Source

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) Source

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) Source

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) Source

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) Source

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) Source

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

FormError

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

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

Parameters

  • targetThe Turbo target id whose element should receive the generated failure block.
  • titlePlain-text failure title. RazorWire HTML-encodes this value.
  • messagePlain-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.") Source

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

Parameters

  • targetThe Turbo target id whose element should receive the generated validation block.
  • modelStateThe MVC model state to render into a validation summary.
  • titlePlain-text summary title. RazorWire HTML-encodes this value.
  • maxErrorsMaximum number of individual validation errors to show before an overflow line is added; values less than zero are treated as zero.
  • messagePlain-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() Source

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) Source

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(int? statusCode = null) Source

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

Parameters

  • statusCodeOptional 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.

Type

RawHtmlStreamAction

Source
Method

RenderAsync

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

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

RazorWireStreamResult

Source

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

Method

ExecuteResultAsync

Task ExecuteResultAsync(ActionContext context) Source

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) Source

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

Source
Method

RenderAsync

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

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

Source
Method

RenderAsync

Task RenderAsync(ViewContext viewContext) Source

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.