Aspnetcore: How to pass more ChildContents from razor file?

Created on 1 Sep 2018  路  6Comments  路  Source: dotnet/aspnetcore

Hello,
I'm playing with ChildContent on a component and can't find solution for following:

Let's have reusable base component allowing to include three parts.
SplitterBase.cshtml

<div class="part1">@Part1</div>
<div class="part2">@Part2</div>
<div class="part3">@Part3</div>

@functions
{
   [Parameter]
   RenderFragment Part1 { get; set; }

   [Parameter]
   RenderFragment Part2 { get; set; }

   [Parameter]
   RenderFragment Part3 { get; set; }

    //just one ChildContent property is not enough in this case
}


```How is it possible to pass the parts from parent component defined in cshtml?
**Splitter.cshtml**


How to define Part1 here?
How to define Part2 here?
How to define Part3 here?

```

area-blazor

Most helpful comment

For anyone who finds this page and is interested in the topic - you might find https://github.com/MarekPokornyOva/BlazorContentProperty as usefull solution.

All 6 comments

Sorry, difficult to manage entering issues in IE11 here.
Here's rest of the description:

Splitter.cshtml```


How to define Part1 here?
How to define Part2 here?
How to define Part3 here?

```

Splitter.cshtml

<SplitterBase>
    How to define Part1 here?
    How to define Part2 here?
    How to define Part3 here?
</SplitterBase>

hi. at the moment a component supports only one RenderFragment and that needs to be named as ChildContent. You can find the info here : https://blazor.net/docs/components/index.html#child-content

At the moment this is a limitation. I believe the team has ideas to provide multi child component hierarchy later down the line. there are other pressing matters on hand for the team to finish first :)

Hope this helps

Hi @lohithgn,
thanks for your reply. I fully understand what development and prioritization means :-). I'm just clarifying where the project is and how well it's possible to use it for "production" projects (with full respect to its experimental status).

Anyway: many thanks to all the team members for their work! Good luck!

What you want to do is possible but with different approach.
You can make child component and use it inside parent as many as you like and pass parameters to control child content from parent.

You can capture children references and manage them from parent as you like.

If this is not clear please provide exact requirements what result you need and I will code when will have time for it.

From markup nesting components is not supported yet as I know.

For anyone who finds this page and is interested in the topic - you might find https://github.com/MarekPokornyOva/BlazorContentProperty as usefull solution.

Was this page helpful?
0 / 5 - 0 ratings