Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4294

Blazor - Parent/Child Component relationship, How to reference Parent properties from Child?

$
0
0

All,

A Blazor page hosts to Components: Component A, Component B. These 2 components are wrappers around 2 HTML drop downs. These components are on the same page but are not nested (I would like to avoid nesting for readability, simplicity).

Component A: Lists Countries.

Component B: Lists Regions.

When the user selects a "Country" in Component A, I would like to read the selected "Country" value from Component A in Component B and have its internal region list filtered based on the selected "Country".

What's the best way to achieve this in Blazor... I am basically looking for solution that allows Component B read component's A selected Country value. I prefer not to use Cascaded parameters since these components are not nested within each other. Also, I would like to stay away from running JS in component B to read value from Component A (the selection could be stored in a hidden field and read using JS).

The only viable solution I see is to use event handlers. Have OnChange event on Component A, and every time a user picks a Country, this event will fire. Then, have an event handler that reads the selection (from Component A) and sets the selected "Country" value on Component B as a filter parameter. Is this the best solution/pattern for this scenario??

These components are designed to use the rendermode webassembly.


Viewing all articles
Browse latest Browse all 4294

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>