Class EnsurePartialViewMacroViewContextFilterAttribute
This is a special filter which is required for the RTE to be able to render Partial View Macros that contain forms when the RTE value is resolved outside of an MVC view being rendered
Inheritance
Namespace: Umbraco.Cms.Web.Common.Filters
Assembly: Umbraco.Web.Common.dll
Syntax
public class EnsurePartialViewMacroViewContextFilterAttribute : ActionFilterAttribute, IActionFilter, IAsyncActionFilter, IResultFilter, IAsyncResultFilter, IOrderedFilter, IFilterMetadata
Remarks
The entire way that we support partial view macros that contain forms isn't really great, these forms need to be executed as ChildActions so that the ModelState,ViewData,TempData get merged into that action so the form can show errors, viewdata, etc... Under normal circumstances, macros will be rendered after a ViewContext is created but in some cases developers will resolve the RTE value in the controller, in this case the Form won't be rendered correctly with merged ModelState from the controller because the special DataToken hasn't been set yet (which is normally done in the UmbracoViewPageOfModel when a real ViewContext is available. So we need to detect if the currently rendering controller is IRenderController and if so we'll ensure that this DataToken exists before the action executes in case the developer resolves an RTE value that contains a partial view macro form.
Methods
View SourceOnActionExecuting(ActionExecutingContext)
Ensures the custom ViewContext datatoken is set before the RenderController action is invoked, this ensures that any calls to GetPropertyValue with regards to RTE or Grid editors can still render any PartialViewMacro with a form and maintain ModelState
Declaration
public override void OnActionExecuting(ActionExecutingContext context)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.AspNetCore.Mvc.Filters.ActionExecutingContext | context |
OnResultExecuting(ResultExecutingContext)
Ensures that the custom ViewContext datatoken is set after the RenderController action is invoked, this ensures that any custom ModelState that may have been added in the RenderController itself is passed onwards in case it is required when rendering a PartialViewMacro with a form
Declaration
public override void OnResultExecuting(ResultExecutingContext context)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.AspNetCore.Mvc.Filters.ResultExecutingContext | context | The filter context. |