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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ISeeUglyCode.Razor.PrettyIf" Version="1.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ISeeUglyCode.Razor.PrettyIf" Version="1.4.0" />
                    
Directory.Packages.props
<PackageReference Include="ISeeUglyCode.Razor.PrettyIf" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ISeeUglyCode.Razor.PrettyIf --version 1.4.0
                    
#r "nuget: ISeeUglyCode.Razor.PrettyIf, 1.4.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ISeeUglyCode.Razor.PrettyIf@1.4.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ISeeUglyCode.Razor.PrettyIf&version=1.4.0
                    
Install as a Cake Addin
#tool nuget:?package=ISeeUglyCode.Razor.PrettyIf&version=1.4.0
                    
Install as a Cake Tool

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>

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last Updated
1.4.0 129 6/3/2026
1.3.0 126 6/3/2026 1.3.0 is deprecated.
1.2.0 126 6/3/2026 1.2.0 is deprecated.
1.1.0 127 6/3/2026 1.1.0 is deprecated.
1.0.0 161 2/3/2026 1.0.0 is deprecated.