Skip to content

Adding asp-route-id to a submit button deactivates the asp-action of a form  #12649

@mauler2025

Description

@mauler2025

The working example below

<form  asp-action="DeleteConfirmed">
     <input type="submit"  value="Delete"  />                    
</form>

public async Task<IActionResult> Delete(int id)
{
  // intentionally removed for simplicity 
}

[HttpPost]
public async Task<IActionResult> DeleteConfirmed(int id)
{
  // intentionally removed for simplicity 
}

no longer works if I add asp-route-id="1" as follows.

<form asp-action="DeleteConfirmed">
     <input type="submit" asp-route-id="1"  value="Delete"  />                    
</form>

public async Task<IActionResult> Delete(int id)
{
  // intentionally removed for simplicity 
}

[HttpPost]
public async Task<IActionResult> DeleteConfirmed(int id)
{
  // intentionally removed for simplicity 
}

To make it work again, I have to explicitly specify asp-action=DeleteConfirmed in the submit button as follows

<form asp-action="AnyTrivialString">
     <input type="submit" asp-route-id="1"  value="Delete"  asp-action="DeleteConfirmed" />                    
</form>

Note: A string assigned to asp-action of the form will be overridden by the submit button. As a result, the form asp-action becomes trivial.

Question

Is it a bug or a known feature?

Minimal Working Example

See my repo here

Metadata

Metadata

Assignees

Labels

✔️ Resolution: By DesignResolved because the behavior in this issue is the intended design.area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions