question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pranavkmcommented, Aug 1, 2019

@pstricks-fans the scenarios you listed make sense:

<!-- Working -->
@*<form asp-action="AnyTrivialString">
    <input type="submit" asp-route-id="1" asp-action="DeleteConfirmed" />
</form>*@


<!-- Not Working -->
<form asp-action="DeleteConfirmed">
    <input type="submit" asp-route-id="1" />
</form>

When you add an asp-route-id on a submit button, it independently determines the Action it would route to. It does not work in tandem with the values you specified in form. 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 the form tag would be the way to go:

<form asp-action="DeleteConfirmed" asp-route-id="1">
    <input type="submit" />
</form>
1reaction
pstricks-fanscommented, Aug 1, 2019

I remove the area to shrink the surface area on which you have to probe.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found