Skip to content

.NET 8 Blazor SSR - Multiple Forms On Page - Field Binding #52360

Open
@sbwalker

Description

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Create a standard component which contains a form. Include 2 instances of this component in a page component - ensuring that each component has a unique form name. Enter information into a field in the first form instance and click Submit. The field in the second form instance will be populated.

image

Expected Behavior

I would expect that the 2 forms would behave independently from one another, since they have unique form names. The field in the second form should remain blank and not be populated with the value from the first form.

Steps To Reproduce

Create app from Blazor Web template. Add StaticForm.razor to /Pages folder and modify Home.razor based on below:

Home.razor

@page "/"

<StaticForm FormName="Form1" />

<StaticForm FormName="Form2" />

StaticForm.razor

<div>Form Name: @FormName</div>

<form method="post" @onsubmit="Submit" @formname="@FormName" data-enhance>
    <AntiforgeryToken />
    <label for="name">Name:</label><br>
    <input type="text" id="name" name="name" class="form-control" @bind="@_name"><br>
    <button type="submit" class="btn btn-primary">Submit</button>
</form>

@if (!string.IsNullOrEmpty(_message))
{
    @((MarkupString)_message)
    
}

@code {
    [Parameter]
    public string FormName { get; set; }

    [SupplyParameterFromForm] public string Name { get => ""; set => _name = value; }

    private string _name;
    private string _message;

    private void Submit()
    {
        _message = $"<br /><p>Form Submitted...Name: {_name}</p>";
    }
}

Exceptions (if any)

No response

.NET Version

8.0.100

Anything else?

It appears that the [SupplyParameterFromForm] attribute is not considering the FormName - it is binding solely based on the name attribute of input elements.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions