Click here to Skip to main content
15,910,277 members
Articles / Web Development / Blazor

Templated Data container with Razor

Rate me:
Please Sign up or sign in to vote.
5.00/5 (10 votes)
26 Jun 2023CPOL2 min read 8.7K   7  
Rather than littering a razor component with @if (a == b) logic to show items, use render fragments to make a declarative component
While writing Blazor components, I got sick of wrapping the visibility of content inside @if.../else logic to show different content when data was present, to when it wasn't. In this simple trick, we are going to look at a handy little method of displaying content depending on whether or not data is present.

Views

Daily Counts

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO
United Kingdom United Kingdom
A developer for over 30 years, I've been lucky enough to write articles and applications for Code Project as well as the Intel Ultimate Coder - Going Perceptual challenge. I live in the North East of England with 2 wonderful daughters and a wonderful wife.

I am not the Stig, but I do wish I had Lotus Tuned Suspension.

Comments and Discussions