Skip to content

Instantly share code, notes, and snippets.

@conficient
Created September 1, 2020 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conficient/5f335ef9418b5a1da6d3f7c1bdd4d6fb to your computer and use it in GitHub Desktop.
Save conficient/5f335ef9418b5a1da6d3f7c1bdd4d6fb to your computer and use it in GitHub Desktop.
Loading content control for Razor
/* shows a loading gif/text if a value is null */
@if (Value == null)
{
<div><img src="/img/SmallLoader.gif" alt="loading" /> Loading</div>
}
else
{
@ChildContent
}
@code {
[Parameter] public RenderFragment ChildContent { get; set; }
[Parameter] public object Value { get; set; }
}
@conficient
Copy link
Author

This gist is to replace all that boilderplate code like this:

@if(someValue is null) 
{
  <p>Loading..</p>
} 
else 
{
 // show actual content
}
@code {
  SomeClass someValue;
}

Instead you can write

<Loading Value="someValue">
  <p>Content goes here</p>
</Loading>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment