'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.
Solution 1:[1]
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!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Andy Braham |