Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable layout for page under Blazor

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?

like image 555
waqasahmed Avatar asked Dec 29 '19 11:12

waqasahmed


People also ask

How do I remove Blazor layout?

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.

How do I use multiple layouts in Blazor?

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.

What's behind the hype about Blazor?

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.


1 Answers

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
like image 158
Osman Avatar answered Oct 11 '22 13:10

Osman