C
C#9mo ago
N0mlss

❔ Blazor: How to have a component inside a component?

I was reading the mudBlazor documentation and I saw that they call a blazor element and inside that element, they call other elements. I didnt know it was even possible and I have no idea how i can do something like that. I would like to call a component and inside that one, call as much component (that is made to work inside the parent one obviously) as I want. As an exemple, I would like to make a table but the number of columns in unknown before run time. Inside the table component, I would like to be able to call multiple element such as textbox or a combobox. Anyway, something like in the picture. Link to the mudblazor component: https://mudblazor.com/components/treeview#basic
MudBlazor
MudBlazor - Blazor Component Library
Blazor Component Library based on Material Design. MudBlazor is easy to use and extend, especially for .NET devs because it uses almost no Javascript.
No description
9 Replies
friedice
friedice9mo ago
you create components and nest them? I'm not sure what your question is oh you want something like this?
<ComponentA>
<ComponentB>
</ComponentA>
<ComponentA>
<ComponentB>
</ComponentA>
This would be componentA.razor
<div>This is component A</div>
@Body

@code {
[Parameter] public RenderFragment Body { get; set; }
}
<div>This is component A</div>
@Body

@code {
[Parameter] public RenderFragment Body { get; set; }
}
this would be componentB.razor
<div>This is component B</div>
<div>This is component B</div>
N0mlss
N0mlss9mo ago
Exactly what i am trying to do!
N0mlss
N0mlss9mo ago
It doesnt work here what i did:
No description
No description
No description
friedice
friedice9mo ago
so it doesnt display anything?
friedice
friedice9mo ago
ASP.NET Core Razor components
Learn how to create and use Razor components in Blazor apps, including guidance on Razor syntax, component naming, namespaces, and component parameters.
N0mlss
N0mlss9mo ago
I forgot to send the error, my mistake. I will try that asap, thanks!!
Anu6is
Anu6is9mo ago
would you be able to use the RowTemplate https://mudblazor.com/components/table#table-with-related-data which is already built in
N0mlss
N0mlss9mo ago
Yeah! I see that blazor librairies have a lot to offer, but i'm trying to understand what is going on behind the scene before starting a project in blazor!
Accord
Accord9mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.