I would like to retrieve the value of a RenderFragment for use in my code:
Parent Component
<SkillIndividual>
<Skill>Fireball</Skill>
<AttributeType>Fire</AttributeType>
</SkillIndividual>
Child Component (SkillIndividual.razor)
<span>@Skill</span> <span class="semi-transparent-text">(@AttributeType)</span>
@code {
[Parameter] public RenderFragment Skill { get; set; }
[Parameter] public RenderFragment AttributeType { get; set; }
private void CheckValue()
{
// Check the value of Skill (Fireball in this case)
}
}
I know I can create [Parameter] public string Skill {get;set;} but I feel like that would ruin the flow of my code. If I can take the value from RenderFragment that would make the code a lot cleaner.
A RenderFragment is a delegate type and you cannot access its constituent parts. Ordinarily, when you want to relate to a child content of a component, you define a single property of type RenderFragment which is named by convention ChildContent.
In short, you cannot extract values from these delagtes. They are to be executed and rendered only. What's the issue with Component parameters ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With