I have a set of 20-30 Blazor components from which I select one to render based on user action elsewhere on the page. I am currently making the selection using an @switch with a "UserChosenKey". Works fine. But to keep the html code a bit more compact,
I'd like to know if there is a way to use a lookup variable (like a Dictionary) so that my 20-30 case switch turns into a single line such as @MyDictonary[UserChosenKey]? I've looked at using RenderFragment for this somehow, but am not clear what it would
take to make this work, if that's even possible/reasonable. Is there a way to do what I would like?
Member
26 Points
63 Posts
Is Dictionary Based Blazor Component Selection Possible
Sep 13, 2020 02:48 PM|CincySteve|LINK
I have a set of 20-30 Blazor components from which I select one to render based on user action elsewhere on the page. I am currently making the selection using an @switch with a "UserChosenKey". Works fine. But to keep the html code a bit more compact, I'd like to know if there is a way to use a lookup variable (like a Dictionary) so that my 20-30 case switch turns into a single line such as @MyDictonary[UserChosenKey]? I've looked at using RenderFragment for this somehow, but am not clear what it would take to make this work, if that's even possible/reasonable. Is there a way to do what I would like?
Thanks. Steve