Skip to main content

Razor Blade Tutorials

Tutorial Home

RazorBlade Safe Attributes API @Tag.Attr v3

Here we'll go through some examples using @Tag.Attr(...)

Creating Simple Attributes

This is a simple demo showing how to add the title and class attribute using code.
It switches between warning/primary depending of the second being odd or even. Refresh the page to see the difference.
If you mouse-over, you'll also see the tooltips showing stuff which would cause trouble otherwise.

1
2
3
4
5
6
<div @Tag.Attr("title", titleWithIssues)
@Tag.Attr("class", cls)
@Tag.Attr("number", 27)>
This is a simple demo showing how to add... <!-- unimportant stuff, hidden -->
</div>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Source Code of this file

Below you'll see the source code of the file. Note that we're just showing the main part, and hiding some parts of the file which are not relevant for understanding the essentials. Click to expand the code

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX