Grahame Horner
Grahame Horner

Reputation: 21

Razor components - cascading parameter values

How do you pass a reference to the parent RenderingFragment to the child component/content when creating a razor component in c# (NOT using .razor) ComponentBase overloading the protected override void BuildRenderTree(RenderTreeBuilder builder) seems not to work as expected.

Upvotes: 1

Views: 702

Answers (1)

bonensoep
bonensoep

Reputation: 107

I had the same question when i wanted to cascade a component to its child components. Solved it as shown below:

builder.OpenComponent<CascadingValue<TValue>>(0);
builder.AddAttribute(1, "Value", this);
builder.AddAttribute(2, "ChildContent", (RenderFragment)((builder2) => {
            builder2.AddContent(3, ChildContent);
        }));
builder.CloseComponent();

Good luck!

Upvotes: 4

Related Questions