ISeeUglyCode.Razor.PrettyIf
1.4.0
dotnet add package ISeeUglyCode.Razor.PrettyIf --version 1.4.0
NuGet\Install-Package ISeeUglyCode.Razor.PrettyIf -Version 1.4.0
<PackageReference Include="ISeeUglyCode.Razor.PrettyIf" Version="1.4.0" />
<PackageVersion Include="ISeeUglyCode.Razor.PrettyIf" Version="1.4.0" />
<PackageReference Include="ISeeUglyCode.Razor.PrettyIf" />
paket add ISeeUglyCode.Razor.PrettyIf --version 1.4.0
#r "nuget: ISeeUglyCode.Razor.PrettyIf, 1.4.0"
#:package ISeeUglyCode.Razor.PrettyIf@1.4.0
#addin nuget:?package=ISeeUglyCode.Razor.PrettyIf&version=1.4.0
#tool nuget:?package=ISeeUglyCode.Razor.PrettyIf&version=1.4.0
ISeeUglyCode.Razor.PrettyIf
Stop breaking your HTML indentation with messy @if blocks. This library provides clean, attribute-based conditional rendering for ASP.NET Core Razor Pages and MVC.
Especially useful when you have a wrapping tag which should be conditional (see Usage section below, point 2).
Targets .NET 8 and .NET 10
Installation
Install the package via the .NET CLI:
dotnet add package ISeeUglyCode.Razor.PrettyIf
Setup
To enable the Tag Helpers in your project, add the following line to your Views/_ViewImports.cshtml (or Pages/_ViewImports.cshtml):
@addTagHelper *, ISeeUglyCode.Razor.PrettyIf
Usage
1. Basic Conditional Rendering
The pretty-if attribute determines if the element (and its children) should be rendered.
<div class="alert alert-danger" pretty-if="@Model.HasErrors">
<strong>Error!</strong> Please check your input.
</div>
2. Transparent Wrappers (The "Link" Pattern)
Use pretty-children to remove the outer tag but keep the content inside if the condition is false.
<a href="@Model.Website"
pretty-if="@(!string.IsNullOrEmpty(Model.Website))"
pretty-children>
@Model.AuthorName
</a>
3. Complex Logic
You can pass any C# boolean expression into the attribute.
<section pretty-if="@(Model.Items.Any() && User.Identity.IsAuthenticated)">
<ul>
@foreach(var item in Model.Items) {
<li>@item.Name</li>
}
</ul>
</section>
4. Conditional output of the child elements
The pretty-children attribute can be set to a boolean expression as well. It defaults to false, and is ignored if pretty-if is true.
5. Alternative tag name if the initial condition is false
The pretty-else attribute can be set to an alternative tag name. It defaults to the empty string, and is ignored if pretty-if is true.
<ol
pretty-if="@ordered"
pretty-else="ul">
@foreach (string item in myList)
{
<li>@item</li>
}
</ol>
Features
- Deterministic Builds: The DLL is byte-for-byte reproducible.
- Source Link: Debug directly into the library source code from GitHub.
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.