Skip to content

Razor does not resolve layout view properly inside area #9895

@thiagomajesk

Description

@thiagomajesk

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:

  1. Run provided repo with dotnet run
  2. Go to area ~/admin
  3. Remove the root Areas\Admin\Views\_Layout.cshtml
  4. 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

Docs states that:

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.

repro.zip

Metadata

Metadata

Assignees

Labels

✔️ Resolution: By DesignResolved because the behavior in this issue is the intended design.area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions