@RenderSection Equivalent in Blazor?

一笑奈何 提交于 2019-12-11 07:34:36

问题


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>
}

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

How can this be done in Blazor?


回答1:


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.

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...




回答2:


I have created a component to get something similar to sections:

https://github.com/inspgadget/BlazorSections



来源:https://stackoverflow.com/questions/57912935/rendersection-equivalent-in-blazor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!