Why _Layout.cshtml placed in ~/Views/Shared folder by default?
I ask this question because I put this file in ~/Views folder and change the Layout value in the _ViewStart.cshtml
@{
Layout = "~/views/_Layout.cshtml";
}
and it still work.
Is it for a special purpose that _Layout.cshtml placed in ~/Views/Shared folder by default?
When the layout page is referenced by its full path, you are right that it makes no difference where it is, as long as it’s somewhere under the ~/Views folder.
One situation where it would matter (but it often doesn’t), is when in your controller action you call the overload of “View()” that allows you to specify an alternate layout (master) page. If that’s the case, and the name specified is a “simple” name, such as “MobileLayout”, the default search path will be first the current controller’s view folder, and then the Shared views folder.
Another much simpler reason is that it “makes sense” in terms of conventions, regardless of any technical requirements.