Adding asp-route-id to a submit button deactivates the asp-action of a form
See original GitHub issueThe 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
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Adding asp-route-id to a submit button deactivates ...
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...
Read more >Why is asp-route-id not working in my form post?
Either the action URL there is wrong or model binding is not working. Typically the parameter would be called id instead of Id...
Read more >Tag Helpers in forms in ASP.NET Core
Describes the built-in Tag Helpers used with Forms. ... <form asp-controller="Demo" asp-action="Register" method="post"> <!
Read more >Avoiding Double Submit of Form in ASP.Net
The basic solution is simple, which is to insert code into the form submit handler that runs the client-side validation and only disables...
Read more >Part 6, controller methods and views in ASP.NET Core
Open the Movies controller and examine the two Edit action methods. The following code shows the HTTP GET Edit method, which fetches the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@pstricks-fans the scenarios you listed make sense:
When you add an
asp-route-id
on asubmit
button, it independently determines the Action it would route to. It does not work in tandem with the values you specified inform
. If you’re attempting to post to two different actions from a single form, using the “working” sample would be the way go. Alternatively, specifying all the route values on theform
tag would be the way to go:I remove the area to shrink the surface area on which you have to probe.