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

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

问题描述

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

 @{布局 = 空}

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

如何在 Blazor 中实现这一点?

解决方案

在我的 Blazor-server-side 项目中,我通过以下两个步骤解决了这个问题.

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

<块引用>

EmptyLayout.razor

@inherits LayoutComponentBase<div class="main"><div class="content px-4">@身体

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

@layout EmptyLayout

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?

解决方案

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

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

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆