In Razor syntax, to disable the layout for a specific page we can do this:
@{
Layout = null
}
In Blazor, the convention for it is defined by @layout
. However, I cannot see how we can set it as null / disable. I wish to apply it to only the index.razor
page.
How can this be achieved in Blazor?
Just create an empty component with the following lines of code. Name the component EmptyLayout. razor. Then reference the EmptyLayout component in your Blazor page.
Blazor by default comes with layouts that are shared across various components, but there are times when building an application you need to have different layouts for various pages, this article will demonstrate how to go about this. Right-click Shared Folder, go to Add, then chose Razor Component.
Blazor is a new client-side UI framework from the ASP.NET team. Its big selling point is the ability to write rich web UI experiences using HTML, CSS, and C# instead of JavaScript—something a lot of developers have been dreaming of.
In my Blazor-server-side
project, i resolved this issue with following two steps.
Step 1: First create a new empty razor component
named EmptyLayout
.
EmptyLayout.razor
@inherits LayoutComponentBase
<div class="main">
<div class="content px-4">
@Body
</div>
</div>
Step 2, To set Layout=null
, I use the below code in the top of all required pages
@layout EmptyLayout
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With