Skip to content

Add WebFormsForm component for interactive-mode Request.Form support #533

@csharpfritz

Description

@csharpfritz

Summary

The Request.Form shim (PR #532) currently only works in SSR mode because interactive Blazor Server has no HTTP POST all interactions flow through SignalR. This means Request.Form["field"] returns empty in interactive mode by design.

Proposal

Create a <WebFormsForm> Blazor component that bridges form submissions to the FormShim via JavaScript interop, enabling Request.Form to work in both SSR and interactive modes.

How it works

Mode Flow
SSR form POST -> IFormCollection -> FormShim (works today)
Interactive WebFormsForm -> JS interop reads FormData -> SignalR -> populates FormShim (new)

Implementation approach

  1. WebFormsForm component wraps a <form> element
  2. JS interop reads FormData from the DOM and sends key/value pairs to C#
  3. FormShim.SetFormData() populates the shim from JS interop data
  4. WebFormsPageBase integration wires the form to Request.Form

Migration story

<!-- Web Forms -->
<form runat="server">
    <asp:TextBox ID="txtName" runat="server" />
</form>

<!-- Blazor with BWFC -->
<WebFormsForm>
    <input type="text" name="txtName" />
</WebFormsForm>

@@code {
    // Same code works in both SSR and interactive mode
    string name = Request.Form["txtName"];
}

Acceptance criteria

  • <WebFormsForm> component renders a <form> element
  • JS interop reads FormData on submit and sends to server
  • Request.Form["field"] returns submitted values in interactive mode
  • Request.Form.GetValues("field") works for multi-value fields
  • Component works in both SSR and interactive render modes
  • bUnit tests for the component
  • Playwright integration tests
  • Sample page demo
  • Documentation update

Dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions