#2 Json Html5 Attributes from code
RazorBlade Advanced JSON Attributes with @Tag.Attr v3
Here we'll go through some more advanced examples using @Tag.Attr(...)
Creating Attributes Containing JSON
This div has an attribute created using an object, because we wanted json. If you look at the source, youll find data-my='{"Name":"razor","Description":"This isn\u0027t your normal text - it has \n line breaks and apostrophes"}'
#2 Json Html5 Attributes from code
@inherits Custom.Hybrid.Razor14
@using ToSic.Razor.Blade;
<!-- unimportant stuff, hidden -->
RazorBlade Advanced JSON Attributes with... <!-- unimportant stuff, hidden -->
Creating Attributes Containing JSON
@{
// this is the object we want in the data-attribute
var myObj = new {
Name = "razor",
Description="This isn't your normal text - it has \n line breaks and apostrophes"
};
}
<div class="alert alert-secondary" @Tag.Attr("data-my", myObj)>
This div has an attribute created using... <!-- unimportant stuff, hidden -->
</div>
<!-- unimportant stuff, hidden -->