Blazor中的@RenderSection是否等效? [英] @RenderSection Equivalent in Blazor?

查看:198
本文介绍了Blazor中的@RenderSection是否等效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Razor页面具有一种机制,您可以在其中引用布局中的命名部分,然后在使用该布局的页面中指定它们.例如,如果您的布局(_Layout.cshtml)如下所示:

Razor pages have a mechanism where you can reference named sections in your layout, and then specify them in your pages that use that layout. For example, if your Layout (_Layout.cshtml) looks like this:

@using...
...
<!DOCTYPE html>
...
<body>
...
@RenderSection("modals", required: false)
...

,然后在仪表板页面中,例如,您将拥有:

and then in your dashboard page, for example, you'd have:

<div>
...
</div>
...
...
@section modals
{
    <div class="modal-container>...</div>
    <div class="modal-container>...</div>
}

会将@section modals...的内容注入到布局中@RenderSection("modals")所在的位置.

that would inject the contents of @section modals... into the place in the layout where @RenderSection("modals") is.

这如何在Blazor中完成?

How can this be done in Blazor?

推荐答案

不幸的是,Blazor当前不支持这种功能. Blazor团队和社区一直在讨论此功能的必要性一年多了,但无济于事. 在此处阅读有关Blazor中各个部分的信息.

Unfortunately, no such feature is currently supported in Blazor. Blazor team and the community have been discussing the necessity of this feature over a year now, but for no avail. Read here about Sections in Blazor.

但是,如果您正在寻找临时解决方案",则可以阅读 SteveAndeson 关于如何将参数值从Blazor组件页面传递到其布局.我知道您正在寻找一种呈现@Body和@EndBody的方法,但是原理保持不变:您必须创建一个布局组件,而不是默认布局

However, if you're looking for a 'temporary solution', you may read a comment by SteveAndeson about how to pass parameter values from a Blazor component page to its layout. I know that you're looking for a way to render the @Body plus @EndBody, but the principal remain the same: You have to create a layout component instead of the default layout

希望这对您有帮助...

Hope this helps...

这篇关于Blazor中的@RenderSection是否等效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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