Error in ASP.NET Core

Simon Leung
Simon Leung used Ask the Experts™
on
Try to create a razor pages in another new created folder "Pages". However, it seems that ASP.NET Core can't recognize it. Any idea ?

I'm using ASP.NET Core.

Thx
Eorro.png
Physical-Folder.png
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Full Stack Developer
Distinguished Expert 2017
Commented:
Have a look at this article: ASP.NET MVC – Controller Subfolder Routing using Attribute Routes


ASP.NET MVC default routing is built upon the DefaultControllerFactory class, which ignores the subfolders inside the root /Controllers/ folder. In other words, it will traverse all controllers under the “Controller” folder and creates a cache using just the class name as the key, thus ignoring any namespace or any subfolder where you have put the controller.

If you need to create routes that take subfolders into account, you will need to do one of the following:

  • Create a new ControllerFactory that will check if the requested controller belongs to any specific namespace and/or subfolder.
  • Add a new global route using the routes.MapRoute()  method in your project’s /App_Start/RouteConfig.cs file
  • Take advantage of the ASP.NET Attribute Routing Feature, firstly introduced in MVC 5 and then re-implemented (with small differences) in ASP.NET MVC 6 / ASP.NET Core as well

There are some proviso's to the bullet points above. Please see the original article for links and explanations.

Author

Commented:
For Razor Pages, the path to the file on disk is used to calculate the URL at which the page can be reached. By convention, all Razor Pages are nested in the Pages directory.
https://www.twilio.com/blog/introduction-asp-net-core-razor-pages

This is a razor pages so I suppose it should able to read in my ASP.NET Core 3...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial