In Blazor, I might often have the same component render on a page twice. Inside this component, I might have <label for="foo">
that refers to an <input id="foo">
in the same component.
Is there a convenient way to set the two IDs to different values per component, but the same value within the component? If each component had a parameter that was different, we could use that, but what about in the case where there is no difference between the parameters' values?
I think I'd have to declare a private instance value, say private Guid ComponentInstanceId {get;} = Guid.NewGuid();
and use that with <label for="foo-@ComponentInstanceId">
...<input id="foo-@ComponentInstanceId">
, but maybe there's a better way?