Bliss.Html.AspNetCore
0.1.0
dotnet add package Bliss.Html.AspNetCore --version 0.1.0
NuGet\Install-Package Bliss.Html.AspNetCore -Version 0.1.0
<PackageReference Include="Bliss.Html.AspNetCore" Version="0.1.0" />
<PackageVersion Include="Bliss.Html.AspNetCore" Version="0.1.0" />
<PackageReference Include="Bliss.Html.AspNetCore" />
paket add Bliss.Html.AspNetCore --version 0.1.0
#r "nuget: Bliss.Html.AspNetCore, 0.1.0"
#:package Bliss.Html.AspNetCore@0.1.0
#addin nuget:?package=Bliss.Html.AspNetCore&version=0.1.0
#tool nuget:?package=Bliss.Html.AspNetCore&version=0.1.0
Bliss.Html.AspNetCore
This library provides a simple abstraction for authoring reusable HTML components in C# and utilizing those components in ASP.NET Core projects.
Example
The following example demonstrates how to create a reusable button component by inheriting from the HtmlElement class.
using Bliss.Html.Core;
public class BootstrapBtn : HtmlElement
{
public BootstrapBtn(string text) : base("button", kids: new Kids { text })
{
Attrs.Add("class", "btn btn-primary");
}
}
// we can create a new instance of our button component
var btn = new BootstrapBtn("Click me");
// when rendered, this will produce the following HTML string:
// => <button class="btn btn-primary">Click me</button>
This is a slightly more complex example that demonstrates how to create a simple card component.
public class BootstrapCard : HtmlElement
{
public BootstrapCard(string title, string body) : base("div")
{
Kids.Add(new HtmlElement("h5",
kids: new Kids { title }));
Kids.Add(new HtmlElement("p",
kids: new Kids { body }));
Attrs.Add("class", "card");
}
}
// we can create a new instance of our card component
var card = new BootstrapCard("Card title", "Some quick example text to build on the card title and make up the bulk of the card's content.");
// when rendered, this will produce the following HTML string:
// => <div class="card">
// <h5>Card title</h5>
// <p>Some quick example text to build on the card title and make up the bulk of the card's content.</p>
// </div>
You can also use the HtmlElement class directly for "one-off" components, like so:
var card = new HtmlElement("div",
attrs: new Attrs
{
{ "class", "card" }
},
kids: new Kids
{
new HtmlElement("h5", kids: new Kids { "Card title" }),
new HtmlElement("p", kids: new Kids { "Some quick example text to build on the card title and make up the bulk of the card's content." })
});
Rendering
Instances of IElement can be returned directly from an ASP.NET Core controller action,
by returning an instance of BlissResult:
using Bliss.Html.AspNetCore;
[Route("/")]
public class HomeController : Controller
{
[HttpGet]
public IActionResult Index()
{
var heading = new HtmlElement("h1", kids: new Kids { "Hello, world!" });
return new BlissResult(heading);
}
}
This will render the IElement as an HTML string to the response body, and set the Content-Type header to text/html.
Bliss.Html.AspNetCore also provides an extension method on the IHtmlHelper interface
called Zap(IElement), which allows consumers to inject IElement instances directly into their Razor views:
@using Bliss.Html.AspNetCore
<h1>Hello, world!</h1>
@await Html.Zap(new BootstrapBtn("Click Me"))
Installation
This library is available as a NuGet package, which can be installed using the following command:
dotnet add package Bliss.Html.AspNetCore
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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 was computed. 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. |
| .NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- Bliss.Html.Core (>= 0.2.0)
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 |
|---|---|---|
| 0.1.0 | 212 | 2/27/2024 |