Skip to content

Async suffix for controller action names will be trimmed by default #14716

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
analogrelay opened this issue Sep 26, 2019 · 0 comments · Fixed by #15044
Closed

Async suffix for controller action names will be trimmed by default #14716

analogrelay opened this issue Sep 26, 2019 · 0 comments · Fixed by #15044
Assignees
Labels
breaking-change Indicates a .NET Core breaking change

Comments

@analogrelay
Copy link

Async suffix for controller action names will be trimmed by default

As part of addressing dotnet/aspnetcore#4849, ASP.NET Core MVC will trim the suffix Async from action names by default. This affects routing and link generation.

Version introduced

3.0

Old behavior

Consider the following ASP.NET Core MVC controller:

public class ProductController : Controller
{
    public async IActionResult ListAsync()
    {
        var model = await DbContext.Products.ToListAsync();
        return View(model);
    }
}

Prior to 3.0, the action will be routeable via Product/ListAsync. Link generation would require specifying the Async suffix e.g.

<a asp-controller="Product" asp-action="ListAsync">List</a>

New behavior

In 3.0, the action will be routeable via Product/List and link generation would require not specifying the Async suffix e.g.

<a asp-controller="Product" asp-action="List">List</a>

This change does not affect names specified using the ActionNameAttribute.

This behavior can be disabled by setting MvcOptions.SuppressAsyncSuffixInActionNames to false as part of the application startup:

services.AddMvc(options =>
{
   options.SuppressAsyncSuffixInActionNames = false; 
});

Reason for change

Asynchronous .NET methods, by convention, end with the Async suffix. However, when a method defines an MVC action, it is generally not desirable to have the Async suffix.

Recommended action

If your application depends on MVC actions retaining the Async suffix in the name, you can:

  • Use ActionNameAttribute to preserve the original name
  • Disable this renaming entirely by setting MvcOptions.SuppressAsyncSuffixInActionNames to false as part of the application startup:
services.AddMvc(options =>
{
   options.SuppressAsyncSuffixInActionNames = false; 
});

Category

  • ASP.NET Core

Affected APIs

Not detectable via API analysis


Issue metadata

  • Issue type: breaking-change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Indicates a .NET Core breaking change
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants