-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
Describe the bug
Razor doesn't seem to be searching inside the Area/Views/Shared
folder when using partial names to define a layout view inside _ViewStart.cshtml
- works only if _Layout.cshtml
is in the area's view root folder.
To Reproduce
Steps to reproduce the behavior:
- Run provided repo with
dotnet run
- Go to area
~/admin
- Remove the root
Areas\Admin\Views\_Layout.cshtml
- See error:
InvalidOperationException: The layout view '/Areas/Admin/Views/_Layout.cshtml' could not be located. The following locations were searched:
/Areas/Admin/Views/_Layout.cshtml
Expected behavior
When a partial name is provided, the Razor view engine searches for the layout file using its standard discovery process. The folder where the handler method (or controller) exists is searched first, followed by the Shared folder. This discovery process is identical to the process used to discover partial views.
Then, the order should be like bellow (but the second one does not seem to be attempted):
/Areas/<Area-Name>/Views/<Controller-Name>
/Areas/<Area-Name>/Views/Shared
/Views/Shared
/Pages/Shared
Also, it does not even report that the framework tried to search inside other folders (like it normally does). I tested against AspNetCore 2.2 and the latest 3.0; the behavior is exactly the same.