string Id { get; set; }
Gets or sets the unique identifier for the Turbo Frame.
Provides extension methods for HttpRequest to detect Turbo requests.
bool IsTurboRequest(this HttpRequest request)
Determines whether the request's Accept header signals a Turbo Stream response.
requestThe HttpRequest to check.true if the Accept header contains "text/vnd.turbo-stream.html", otherwise false.
A fluent builder for creating Turbo Stream responses.
RazorWireStreamBuilder Append(string target, string templateHtml)
Queues an append action that inserts the provided HTML into the specified target element.
targetThe target DOM selector or element identifier to which the HTML will be appended.templateHtmlThe HTML fragment to append inside the target's template.The same RazorWireStreamBuilder instance to allow fluent chaining.
RazorWireStreamBuilder AppendPartial(string target, string viewName, object? model = null)
Queues an action to append the rendered partial view to the specified DOM target.
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.The current RazorWireStreamBuilder instance for fluent chaining.
RazorWireStreamBuilder Prepend(string target, string templateHtml)
Queues a raw HTML prepend action targeting the specified DOM element.
targetThe DOM target selector or identifier to receive the content.templateHtmlThe HTML content to insert before the target element's existing content.The builder instance for fluent chaining.
RazorWireStreamBuilder PrependPartial(string target, string viewName, object? model = null)
Queues an action to prepend the rendered partial view into the specified DOM target.
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.The current RazorWireStreamBuilder instance for fluent chaining.
RazorWireStreamBuilder Replace(string target, string templateHtml)
Queues a raw HTML replace action targeting the specified DOM element.
targetThe DOM element selector or identifier to target.templateHtmlThe HTML content used to replace the target's contents.The current RazorWireStreamBuilder instance.
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.
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.The same RazorWireStreamBuilder instance for fluent chaining.
RazorWireStreamBuilder Update(string target, string templateHtml)
Queues a raw HTML "update" turbo-stream action for the specified DOM target using the provided HTML template.
targetThe DOM target selector or identifier to apply the update to.templateHtmlThe HTML fragment to use as the action's template.The same RazorWireStreamBuilder instance for fluent chaining.
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.
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.The builder instance for further chaining.
RazorWireStreamBuilder AppendComponent<T>(string target, object? arguments = null)
Queues an append action that will render the specified view component into the given DOM target.
TThe ViewComponent type to render.targetThe DOM element selector or identifier to target for the append action.argumentsOptional arguments passed to the view component when rendering.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.
targetThe DOM element selector or identifier to target.componentNameThe name of the view component to render.argumentsOptional arguments to pass to the view component.The current RazorWireStreamBuilder instance for method chaining.
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.
TThe view component type to render.targetThe DOM target selector or identifier to prepend the component into.argumentsOptional arguments passed to the view component.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.
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.The current builder instance for fluent chaining.
RazorWireStreamBuilder ReplaceComponent<T>(string target, object? arguments = null)
Queues a view component replace action targeting the specified DOM element.
targetThe DOM target selector or identifier to apply the replace action to.argumentsOptional arguments to pass to the view component.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.
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.The same RazorWireStreamBuilder instance for fluent chaining.
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.
TThe view component type to render.targetThe DOM element selector or identifier that the turbo-stream will target.argumentsOptional arguments to pass to the view component.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.
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.The builder instance for fluent chaining.
RazorWireStreamBuilder Remove(string target)
Queues a remove action targeting the specified DOM element.
targetThe DOM target selector or identifier whose element will be removed.The current RazorWireStreamBuilder instance for fluent chaining.
string Build()
Builds a single concatenated Turbo Stream markup string from the queued raw HTML actions.
The concatenated Turbo Stream markup representing the queued raw HTML actions.
InvalidOperationExceptionThrown if the builder contains actions that require asynchronous rendering (such as partial views or view components); use RenderAsync(viewContext) or BuildResult() instead.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.
viewContextThe view rendering context to use for each action.cancellationTokenToken to observe for cancellation.The concatenated HTML string produced by rendering each queued action.
RazorWireStreamResult BuildResult()
Creates a RazorWireStreamResult containing the builder's queued stream actions and associated controller.
A RazorWireStreamResult initialized with a copy of the queued actions and the builder's controller.
Task<string> RenderAsync(Microsoft.AspNetCore.Mvc.Rendering.ViewContext viewContext, CancellationToken cancellationToken = default)
Renders the action as a turbo-stream HTML string.
viewContextThe rendering context used when rendering the action.cancellationTokenCancellation token (ignored for raw HTML).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.
Implements IRazorPartialRenderer using the Razor view engine.
Task<string> RenderPartialToStringAsync(string viewName, object? model = null, CancellationToken cancellationToken = default)
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.
An IActionResult that renders and streams Turbo Stream actions to the response.
Task ExecuteResultAsync(ActionContext context)
Streams rendered Turbo Stream HTML for the configured actions to the HTTP response.
contextThe current action context used to build the view context and access the HTTP response.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.
ViewContext CreateViewContext(ActionContext actionContext)
Creates a ViewContext configured for rendering the stream actions, optionally inheriting ViewData and TempData from the associated controller.
actionContextThe current ActionContext used to build the ViewContext.A ViewContext configured with a NullView, the prepared ViewData, TempData (the controller's if available or obtained from ITempDataDictionaryFactory), TextWriter.Null, and default HtmlHelperOptions.
Task<string> RenderAsync(ViewContext viewContext, CancellationToken cancellationToken = default)
Produces the stored raw HTML as the rendered output for the given view context.
viewContextThe view rendering context supplied to the action.cancellationTokenCancellation token (ignored for raw HTML).The stored HTML string.
Task RenderAsync(ViewContext viewContext)
Performs no rendering and completes immediately.
viewContextThe rendering context provided by the framework; this implementation ignores it.A completed Task representing the finished render operation.
Represents an action to be performed in a RazorWire stream (e.g., append, replace).
Task<string> RenderAsync(ViewContext viewContext, CancellationToken cancellationToken = default)
Renders the stream action to an HTML string using the provided view rendering context.
viewContextThe Razor view rendering context used to produce the HTML output.cancellationTokenA token to observe while waiting for the task to complete.The rendered HTML for this stream action.
Internal helper for rendering view components into Turbo Stream fragments.
Task<string> RenderComponentStreamAsync(ViewContext viewContext, string action, string target, dynamic componentIdentifier, object? arguments)
Renders a view component into a Turbo Stream XML fragment.
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.A Turbo Stream XML fragment whose `action` and `target` attributes are HTML-encoded and whose <template> contains the rendered component HTML.
A Turbo Stream action that renders a view component by its Type.
Task<string> RenderAsync(ViewContext viewContext, CancellationToken cancellationToken = default)
Renders the configured view component into a Turbo Stream fragment.
viewContextThe current MVC view context used to execute and render the view component.cancellationTokenA token to observe while deciding whether to proceed.A string containing a <turbo-stream> element whose action and target attributes are HTML-encoded and whose <template> contains the component's rendered HTML.
A Turbo Stream action that renders a view component by its name.
Task<string> RenderAsync(ViewContext viewContext, CancellationToken cancellationToken = default)
Render the configured view component (by name) into a Turbo Stream fragment.
viewContextThe current Razor view context used to execute and render the view component.cancellationTokenA token to observe while waiting for the task to complete.A string containing a <turbo-stream> element whose action and target attributes are HTML-encoded and whose <template> contains the rendered component HTML.
Provides static methods for creating Turbo Frame results and RazorWire stream builders.
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.
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.A PartialViewResult that renders the RazorWire/_TurboFrame partial populated with the specified id, partial view, and model.
Also exposes the frame identifier by setting controller.ViewData["TurboFrameId"].
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"].
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.A PartialViewResult that renders the RazorWire/_TurboFrame partial with a TurboFrameViewModel.
RazorWireStreamBuilder CreateStream()
Creates a new RazorWireStreamBuilder for fluidly configuring and producing Turbo Stream actions.
A new RazorWireStreamBuilder instance ready to configure stream updates.
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.
controllerThe controller whose context and data are used as the basis for the new Microsoft.AspNetCore.Mvc.Rendering.ViewContext.A Microsoft.AspNetCore.Mvc.Rendering.ViewContext configured with the controller's data and a no-op view.
Task RenderAsync(Microsoft.AspNetCore.Mvc.Rendering.ViewContext viewContext)
A no-op view that does not render any content.
viewContextThe view context provided for rendering; this implementation ignores it.A completed Task.
Data model used for rendering the Turbo Frame partial view.
string Id { get; set; }
Gets or sets the unique identifier for the Turbo Frame.
string? PartialView { get; set; }
Gets or sets the name of the partial view to render inside the frame, if any.
string? ViewComponent { get; set; }
Gets or sets the name of the view component to render inside the frame, if any.
object? Model { get; set; }
Gets or sets the optional model to pass to the partial view or view component.
Provides a mechanism to render Razor partial views to strings, specifically useful for background services and non-HTTP request contexts.
Task<string> RenderPartialToStringAsync(string viewName, object? model = null, CancellationToken cancellationToken = default)
Renders a partial view as an HTML string.
viewNameThe name or path of the partial view to render.modelOptional model to pass to the view.cancellationTokenA token to monitor for cancellation requests.A task that represents the asynchronous render operation. The task result contains the rendered HTML string.
A Turbo Stream action that renders a partial view as its content.
Task<string> RenderAsync(ViewContext viewContext, CancellationToken cancellationToken = default)
Renders the configured partial view and wraps its output in a Turbo Stream element.
viewContextThe current view context used to locate services and render the partial view.cancellationTokenA token to observe while waiting for the task to complete.The turbo-stream HTML string containing the rendered partial inside a <template> element.
InvalidOperationExceptionThrown if the partial view cannot be located.