Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subjects - Lists via templated razor components to hide/show w/o if/then #40

Open
goodtocode opened this issue Jul 9, 2023 · 0 comments
Assignees

Comments

@goodtocode
Copy link
Owner

goodtocode commented Jul 9, 2023

Subjects - Lists via templated razor components to hide/show w/o if/then

https://www.codeproject.com/Tips/5363626/Templated-Data-container-with-Razor

`public class DataContainer : ComponentBase
{
[Parameter] public bool HasData { get; set; }

[Parameter] public RenderFragment DataTemplate { get; set; } = null!;

[Parameter] public RenderFragment NoData { get; set; } = null!;

protected override void BuildRenderTree(RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
builder.AddContent(0, HasData ? DataTemplate : NoData);
}
}`

<DataContainer HasData="@(_value > 0)"> <NoData> <p>There is no data</p> </NoData> <DataTemplate> <div class="mb-8"> <p>There is content here</p> </div> </DataTemplate> </DataContainer>

@goodtocode goodtocode self-assigned this Jul 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant