Skip to content

Render the web context control

Emit the hidden/visible web-context form used to round-trip context id and value. Trigger: Razor view calling the helper.

Field Value
Operation ID OP-20
Trigger Razor view calling the helper
Inputs WebContextViewModel
Outputs <form id="frmWebContext"> markup written to the view writer
Primary components WebContextExtensions.RenderWebContext(HtmlHelper, WebContextViewModel)
Entry point src/Web.Mvc/Extensions/WebContextExtensions.cs

Steps

  1. Enforce.ArgumentNotNull on helper and model (BR-01).
  2. Emit <form id="frmWebContext">, adding style="display: none;" when model.ShowContextBox is false. WebContextViewModel defaults ShowContextBox to true (BR-46).
  3. Emit hidden input WebContextId with model.ContextId — the value OP-01 step 3 later reads back from the form.
  4. Emit text input WebContextValue with model.ContextValue and class input-sm form-control — the value OP-01 step 7 reads back.
  5. Write the markup to helper.ViewContext.Writer.

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start([Razor view calls RenderWebContext])
    Guard[Guard helper/model]
    Form["Emit form, hidden if ShowContextBox false"]
    Hidden[Emit WebContextId hidden input]
    Text[Emit WebContextValue text input]
    Write[Write markup]
    EndOk([Markup emitted])
    Start --> Guard
    Guard --> Form
    Form --> Hidden
    Hidden --> Text
    Text --> Write
    Write --> 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/Extensions/WebContextExtensions.cs