user2501749
user2501749

Reputation: 33

Hide section of a Parent component if child component is not generating any markup in Blazor App

I have a parent component in Blazor in which child component is placed.

<div class="margin-top-50">
  <ChildComponent someparameters/>
</div> 

Now if the child component is not generating any markup based upon parameters passed, I don't want to render the div tag also in the parent component. How can I achieve this?

Upvotes: 1

Views: 406

Answers (1)

arconaut
arconaut

Reputation: 3285

Would it be an option to put the outer div inside of ChildComponent?

Inside ChildComponent.razor

<div class="margin-top-50">
  ... the rest of the component as it is now
</div> 

In case you render that component somewhere else, and you don't need the div there, then you can remove the margin in the component based on the passed in parameters - the same parameters that define whether there's any markup being generated.

Upvotes: 1

Related Questions