Skip to content

asp-action behave differently between ASP.NET Core 2.2 and 3.1 when Action Method has Async suffix #21216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TheBlueSky opened this issue Apr 26, 2020 · 2 comments
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved
Milestone

Comments

@TheBlueSky
Copy link

TheBlueSky commented Apr 26, 2020

While upgrading an application from ASP.NET Core 2.2 to 3.1 I noticed that asp-action TagHelper behave differently in these versions.

I am not sure this is intentional or not, or whether it was announced as a breaking change or not. Also, not sure if this issue is talking about the same thing or not; in my case, the link is not generated at all.

Describe the bug

In ASP.NET Core 2.2, when using the Action Method name with asp-action TagHelper, the link is generated as expected. However, in ASP.NET Core 3.1, no link is generated if the Action Method has Async suffix.

For more details, see "To Reproduce" section.

To Reproduce

  1. Create an ASP.NET Core 2.2 Razor Pages application.
  2. Add the Controller code; see Controller code below.
  3. Add a link in Index.cshtml; see HTML code below.
  4. Run the application and see that the link is generated correctly for /Account/Logout.
// Controller code
public sealed class AccountController : Controller
{
    [Route("/Logout")]
    public async Task<IActionResult> LogoutAsync()
    {
        await this.HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

        return this.RedirectToPage(ApplicationConstants.IndexPage);
    }
}
<!-- HTML code -->
<a asp-controller="Account" asp-action="LogoutAsync">Logout</a>

Repeat the same steps, but now create an ASP.NET Core 3.1. Run the application and see that there is no link generated and the rendered anchor tag is:

<a href="">Logout</a>

Lastly, remove Async from asp-action TagHelper:

<!-- HTML code -->
<a asp-controller="Account" asp-action="Logout">Logout</a>

Run the application and see that the link is generated as expected.

@mkArtakMSFT mkArtakMSFT added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates question labels Apr 27, 2020
@TheBlueSky TheBlueSky changed the title asp-action behave differently between ASP.NET Core 2.2 and 3.1 with Attribute Routing asp-action behave differently between ASP.NET Core 2.2 and 3.1 when Action Method has Async suffix Apr 27, 2020
@pranavkm pranavkm added ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. and removed question labels Apr 28, 2020
@ghost ghost added the Status: Resolved label Apr 28, 2020
@pranavkm pranavkm added this to the Discussions milestone Apr 28, 2020
@TheBlueSky
Copy link
Author

Thanks, Pranav; I should have completed the document until the end I guess :p

@ghost ghost locked as resolved and limited conversation to collaborators May 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved
Projects
None yet
Development

No branches or pull requests

3 participants