<div class="form-inline justify-content-center mt-4">
@if (Products != null && Products.Any())
{
@foreach (var product in Products)
{
#MyCode
}
}
else
{
<h2>This Store has no Products :)</h2>
}
</div>
@code
{
[Parameter]
public int Id { get; set; }
public IEnumerable<ProductDTO> Products { get; set; }
protected override async Task OnInitializedAsync()
{
Products = await Store.GetStoreProducts(Id);
}
}
It first show the else part and then load the if part ( if products are available ). It should work like that if products are available then else part shouldn't be loaded.