Skip to content

.NET 8 Blazor - Form With Multiple Buttons Inconsistent Behavior #53993

Closed
@sbwalker

Description

@sbwalker

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Blazor exhibits inconsistent behavior when handling forms with multiple buttons. The following is an example form which contains 2 buttons. When a user clicks on a button the component should tell the user which button was clicked:

<form method="post" @onsubmit="Submit" @formname="MyUniqueFormName">
    <AntiforgeryToken />
    <button type="submit" class="btn btn-primary" name="Action" value="Action1">Action1</button>
    <button type="submit" class="btn btn-primary" name="Action" value="Action2">Action2</button>
</form>

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

@code {
    [SupplyParameterFromForm] public string Action { get; set; }

    private string _message;

    private void Submit()
    {
        _message = $"<br /><p>";
        _message += "Action: " + ((Action != null) ? Action : "NULL");
        _message += "</p>";
    }
}

Running this code using Static rendering works correctly - it displays an action of “Action1” or “Action2” depending on which button is clicked:

304223049-150c5611-7276-412f-af52-68d6fa290582

However, running this code with Interactive rendering, the action always returns NULL.

304223089-a7cbb1c7-141f-4131-b53d-3dba698e967a

Expected Behavior

Regardless of the render mode being used, form handling should be consistent. In this example it should return the action related to the button clicked.

Steps To Reproduce

Sample component code is included in the issue report. The component would need to be instantiated using Interactive render mode to reproduce the problem reported.

Exceptions (if any)

No response

.NET Version

8.0.1

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions