I use blazor server side whit visual studio 2022. I use MainLayout.razor as the default layout. but I dont understand what is _layout.cshtml in Pages folder and Pages\Shared folder use? Thanks.
- 1The _layout.cshtml is for ASP.NET MVC pages I think you don't need it for BlazorSantiago– Santiago2022-05-27 22:04:46 +00:00Commented May 27, 2022 at 22:04
- When you mean "in Areas\Identity\Pages\Shared" you should spell that out.Henk Holterman– Henk Holterman2022-05-28 08:43:18 +00:00Commented May 28, 2022 at 8:43
Add a comment |
2 Answers
In .Net 6 Blazor project
MainLayout.razor :
MainLayout is used for default layout which is render in all blazor component, if we want to render other layout in some pages that time we need to specify layout.
MainLayout is used for set common content in single page
@layout EmptyLayout
as above we need to declare layout for specific components.
_Layout.cshtml:
- Lower version of .Net 6 in Blazor we have _host.cshtml file in blazor project but in .Net 6 we have _layout and _host both file , as below _layout file is call from _host.
- Here is the code of _host.cshml
@namespace admin_app.Pages @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers @{ Layout = "_Layout"; } <component type="typeof(App)" render-mode="Server" /> - Lower version of .Net6 these content set inside _host file, now _layout file is used for declare common css, js and common content which are used in all whole website.
- We also create javascript function inside our _layout file.