Request.Form Migration

This sample demonstrates the FormShim that provides Web Forms-compatible Request.Form access in Blazor. The shim wraps IFormCollection and exposes the same NameValueCollection-style API used in Web Forms code-behind.

📋 SSR Note: This page uses Static Server Rendering (SSR) via [ExcludeFromInteractiveRouting] so that the HTML form submits via a real HTTP POST — exactly how Web Forms worked. Request.Form values are populated from the POST body, just like Request.Form in ASP.NET Web Forms.

Try It — Submit the Form

Fill in the fields below and click Submit Form. The values will be read using Request.Form and displayed in the results section.

User Profile Form

Before / After Code Comparison

1. Basic Form Field Access

Before (Web Forms)
// In Page_Load or button click handler
string username = Request.Form["username"];
string email = Request.Form["email"];
if (username != null)
{
    lblGreeting.Text = "Hello, " + username;
}
After (Blazor with BWFC)
// Same code works in SSR mode!
string username = Request.Form["username"];
string email = Request.Form["email"];
if (username != null)
{
    greeting = "Hello, " + username;
}
// TODO(bwfc-general): Migrate to EditForm + @bind
// for full interactive Blazor support.

2. Multi-Value Fields (GetValues)

Before (Web Forms)
// Get all selected checkbox values
string[] colors = Request.Form.GetValues("colors");
if (colors != null)
{
    foreach (string color in colors)
    {
        // process each selected color
    }
}
After (Blazor with BWFC)
// Same call works in SSR mode!
string[] colors = Request.Form.GetValues("colors");
if (colors != null)
{
    foreach (string color in colors)
    {
        // process each selected color
    }
}
// TODO(bwfc-general): Migrate to @bind with
// List<string> for interactive checkbox groups.

3. Form Metadata

Before (Web Forms)
// Inspect form contents
string[] keys = Request.Form.AllKeys;
int fieldCount = Request.Form.Count;
bool hasName = Request.Form.AllKeys.Contains("name");
After (Blazor with BWFC)
// Same properties available!
string[] keys = Request.Form.AllKeys;
int fieldCount = Request.Form.Count;
bool hasName = Request.Form.ContainsKey("name");

Migration Guidance

The Request.Form shim enables your Web Forms code to compile in Blazor without changes. For full interactive support, migrate to Blazor's EditForm and @bind pattern. The shim works as a stepping stone during migration.

Web Forms / BWFC Shim
// Works in SSR, returns null in interactive
string name = Request.Form["name"];
string email = Request.Form["email"];

// Process the form data
if (name != null)
{
    SaveUser(name, email);
}
Full Blazor (target state)
// Interactive-friendly with two-way binding
<EditForm Model="@formModel" OnValidSubmit="HandleSubmit">
    <InputText @bind-Value="formModel.Name" />
    <InputText @bind-Value="formModel.Email" />
    <button type="submit">Submit</button>
</EditForm>

@code {
    private UserModel formModel = new();
    private void HandleSubmit()
    {
        SaveUser(formModel.Name, formModel.Email);
    }
}
Migration Path Summary
Web Forms Pattern BWFC Shim (compiles now) Full Blazor (target)
Request.Form["field"] Same — works in SSR @bind-Value on InputText
Request.Form.GetValues("checkboxes") Same — works in SSR @bind with List<string>
Request.Form.AllKeys Same — works in SSR Model properties / reflection
Request.Form.Count Same — works in SSR Model-based validation

Tip: Use // TODO(bwfc-general): Migrate to EditForm + @bind comments alongside your shim code to track what needs updating for full Blazor interactivity.