Skip to main content
Home  › ... Razor

Razor Blade Tutorials

Tutorial HomeRazor.Blade
#3 Use Scrub to remove Tag-Attributes, Classes, Styles or whatever you need

RazorBlade IScrub.Attributes(...), IScrub.Styles(), IScrub.Classes()

These demos show how to scrub attributes of html source.

Get IScrub service


@{
  var scrubSvc = GetService<IScrub>();
}

Scrub classes

Using IScrub.Classes(source) you can scrub all classes.

Scrub all classes from source: <div ><strong >No</strong> classes allowed</div>

@{
  var exampleClasses = "<div class='remove-me not-allowed'><strong class='not-allowed'>No</strong> classes allowed</div>";
}
<div><strong>Scrub all classes from source: </strong><code>@scrubSvc.Classes(exampleClasses)</code></div>

Scrub attributes

Using IScrub.Attributes(source, attributes) you can scrub attributes.

Scrub all attributes from source: <div>No attributes allowed</div>
Scrub one attribute from source: <div not-allowed class='removed'>No attributes allowed</div>
Scrub some attributes from source: <div class='removed'>No attributes allowed</div>

@{
  var exampleAttributes = "<div remove-me not-allowed class='removed'>No attributes allowed</div>";
}
<div><strong>Scrub all attributes from source: </strong><code>@scrubSvc.Attributes(exampleAttributes)</code></div>
<div><strong>Scrub one attribute from source: </strong><code>@scrubSvc.Attributes(exampleAttributes, "remove-me")</code></div>
<div><strong>Scrub some attributes from source: </strong><code>@scrubSvc.Attributes(exampleAttributes, new string[] { "remove-me", "not-allowed" })</code></div>

Scrub styles

Using IScrub.Styles(source) you can scrub all styles.

Scrub all styles from source: <div >No styles allowed</div>

@{
  var exampleStyle = "<div style='background-color: red; width: 50px; height: 50px;'>No styles allowed</div>";
}
<div><strong>Scrub all styles from source: </strong><code>@scrubSvc.Styles(exampleStyle)</code></div>
#3 Use Scrub to remove Tag-Attributes, Classes, Styles or whatever you need

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

@inherits Custom.Hybrid.Razor12
@using ToSic.Razor.Blade;
@using ToSic.Sxc.Services;
<!-- unimportant stuff, hidden -->
<div class="row">
  <div class="col-md-7">
    RazorBlade IScrub.Attributes(...)... <!-- unimportant stuff, hidden -->
  </div>
  <div class="col-md-5">
    @Html.Partial("../shared/_InfoSection.cshtml", new { Data = viewMd.Specs.Requirements, Title = "Requirements", Icon = "fa-exclamation-circle" })
    @Html.Partial("../shared/_InfoSection.cshtml", new { Data = viewMd.Specs.Resources, Title = "Resources" })
  </div>
</div>

Get IScrub service

@{
  var scrubSvc = GetService<IScrub>();
}



Scrub classes Using... <!-- unimportant stuff, hidden -->

@{
  var exampleClasses = "<div class='remove-me not-allowed'><strong class='not-allowed'>No</strong> classes allowed</div>";
}
<div><strong>Scrub all classes from source: </strong><code>@scrubSvc.Classes(exampleClasses)</code></div>



Scrub attributes Using... <!-- unimportant stuff, hidden -->

@{
  var exampleAttributes = "<div remove-me not-allowed class='removed'>No attributes allowed</div>";
}
<div><strong>Scrub all attributes from source: </strong><code>@scrubSvc.Attributes(exampleAttributes)</code></div>
<div><strong>Scrub one attribute from source: </strong><code>@scrubSvc.Attributes(exampleAttributes, "remove-me")</code></div>
<div><strong>Scrub some attributes from source: </strong><code>@scrubSvc.Attributes(exampleAttributes, new string[] { "remove-me", "not-allowed" })</code></div>



Scrub styles Using IScrub.Styles(source)... <!-- unimportant stuff, hidden -->

@{
  var exampleStyle = "<div style='background-color: red; width: 50px; height: 50px;'>No styles allowed</div>";
}
<div><strong>Scrub all styles from source: </strong><code>@scrubSvc.Styles(exampleStyle)</code></div>



<!-- unimportant stuff, hidden -->