Search code examples
asp.net-core-mvc

Is there a known bug with ASP.NET Core 7 MVC web app where it does not recognize GetAllAsync method naming convention?


I'm doing an ASP.NET Core 7 MVC app for the first time, something I know how to do in .NET 4.7.2, and basically I didn't get far as, the very first View I'd normally do for some reason returned blank.

Usually I first create a GetAllAsync() method in the controller which returns View(list), and I add a GetAllAsync.cshtml view to display it. "Add View" wizard so far always did the basic job fine.

Now the generated page returned blank.

So I did some testing. Made extra methods to check if there are routing issues, played with different view files, different simple methods, redid the whole project as well ... only to get to the bright idea of renaming the GetAllAsync method and GetAllAsync.cshtml to Lemon method and Lemon.cshtml, some random term.

And this solved it. As long as I avoid using the naming convention GetAllAsync, I don't encounter issues.

But I don't understand why. Does anybody know what is going on?

I've yet to proceed with the CRUD, so I don't know if Edit, Delete, Create, GetById and such will behave the same or not.


Solution

  • In ASP.NET Core 3.0, ASP.NET Core MVC removes the Async suffix from controller action names. Here is the official link: Async suffix removal from controller action names

    As for the normal naming of Edit, Delete, Create, GetById, it will not be affected. In projects after asp.net core 3.1, as long as the .cshtml files are not named with the Async ending, you will not encounter the current problem.