mvc • Razor.NET - martindubenet/wed-dev-design GitHub Wiki

Razor.101

Coding Tips and Tricks

Remembering what I once knew ;)

Conditional statements

IF inline

@(varName ? "ifTrue_thisString" : "orElse_thatString" )

@Html.Raw(varName ? "<i class="fas thumbs-up"></i>" : "<i class="fas thumbs-down"></i>")

<* class="@(ViewBag.Theme == null ? "appTheme" : "customTheme")">...</*>

IF + ELSE block

@if (varName) {
    <code class="ifTrue">thisHTML</code>
}
else
{
    <code class="orElse">thatHTML</code>
}
⚠️ **GitHub.com Fallback** ⚠️