Skip to content

Project web context onto the view model

Copy the resolved web context onto the current view model after the action executes. Trigger: MVC action-filter pipeline, after the action result is produced.

Field Value
Operation ID OP-02
Trigger MVC action-filter pipeline, after the action result is produced
Inputs filterContext.Controller.ViewData.Model, resolved WebContext
Outputs WebContextViewModelBase.WebContext.ContextId / .ContextValue populated
Primary components WebContextControllerBase.OnActionExecuted(ActionExecutedContext)
Entry point src/Web.Mvc/Controllers/WebContextControllerBase.cs

Steps

  1. Cast ViewData.Model to WebContextViewModelBase; a null cast result means the model does not participate in web context and the step is skipped (BR-06).
  2. If both the model and WebContext are non-null, copy WebContext.ContextId into model.WebContext.ContextId and WebContext.CurrentValue into model.WebContext.ContextValue.
  3. Call base.OnActionExecuted(filterContext).

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start([Action result produced])
    Cast[Cast ViewData.Model to WebContextViewModelBase]
    Chk{Model and WebContext non-null?}
    Copy[Copy ContextId/ContextValue]
    Skip([Skip decoration])
    EndOk([Continue])
    Start --> Cast
    Cast --> Chk
    Chk -->|Yes| Copy
    Chk -->|No| Skip
    Copy --> EndOk
    Skip --> EndOk

Failure and edge-case behavior

  • No unexpected failure paths beyond argument-guard exceptions and delegated dependency behavior were identified for this operation.

Sources

  • src/Web.Mvc/Controllers/WebContextControllerBase.cs