禁用Blazor下页面的布局 [英] Disable layout for page under Blazor

查看:81
本文介绍了禁用Blazor下页面的布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Razor语法,要禁用特定页面的布局,我们可以这样做:

In Razor syntax, to disable the layout for a specific page we can do this:

  @{
    Layout = null
  }

在Blazor中,其约定由 @layout 定义.但是,我看不到如何将其设置为null/disable.我希望将其仅应用于 index.razor 页面.

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.

这在Blazor中如何实现?

How can this be achieved in Blazor?

推荐答案

在我的 Blazor服务器端项目中,我通过以下两个步骤解决了此问题.

In my Blazor-server-side project, i resolved this issue with following two steps.

步骤1:首先创建一个名为 EmptyLayout 的新的空 razor组件.

Step 1: First create a new empty razor component named EmptyLayout.

EmptyLayout.razor

EmptyLayout.razor

@inherits LayoutComponentBase

<div class="main">    
    <div class="content px-4">
        @Body
    </div>
</div>

第2步,要设置 Layout = null ,我在所有必填页面的顶部使用以下代码

Step 2, To set Layout=null, I use the below code in the top of all required pages

@layout EmptyLayout

这篇关于禁用Blazor下页面的布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆