Projektanker.RazorComponents 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Projektanker.RazorComponents --version 1.0.0                
NuGet\Install-Package Projektanker.RazorComponents -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Projektanker.RazorComponents" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Projektanker.RazorComponents --version 1.0.0                
#r "nuget: Projektanker.RazorComponents, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Projektanker.RazorComponents as a Cake Addin
#addin nuget:?package=Projektanker.RazorComponents&version=1.0.0

// Install Projektanker.RazorComponents as a Cake Tool
#tool nuget:?package=Projektanker.RazorComponents&version=1.0.0                

Razor Components

Razor Components is an ASP.NET Core library that allows you to write UI components while maintaining compatibility with Razor Pages and MVC.

Installation

Razor Components works by using tag helpers.
As with all tag helpers, you will need to go to the _ViewImports.cshtml file and add a reference to the package's and your project's namespace like so:

@addTagHelper *, Projektanker.RazorComponents
@addTagHelper *, Example.Web

Usage

Basic usage without child content

Given folder structure:

~/Views/Components
  - HelloWorld.cshtml
  - HelloWorld.cshtml.cs

HelloWorld.cshtml.cs:

namespace Sample.Web.Views.Components;

[HtmlTargetElement("HelloWorld")]
public class HelloWorld : RazorComponentTagHelper
{
    public string Greeting { get; set; } = string.Empty;
}

HelloWorld.cshtml:

@using Sample.Web.Views.Components
@model HelloWorld
<p>
  <strong>@Model.Greeting</strong> World
</p>

You would use it like this:

<HelloWorld greeting="Hello" />

Basic usage with single child content

Given folder structure:

~/Views/Components
  - Button.cshtml
  - Button.cshtml.cs

Button.cshtml.cs:

namespace Sample.Web.Views.Components;

[HtmlTargetElement("Button")]
public class Button : RazorComponentTagHelper
{
}

Button.cshtml:

@using Sample.Web.Views.Components
@model Button
<button class="btn btn-primary">
  @Model.ChildContent
</button>

You would use it like this:

<Button>
  Click me
</Button>

Advanced usage with named slots

Given folder structure:

~/Views/Components
  - Card.cshtml
  - Card.cshtml.cs

Card.cshtml.cs:

namespace Sample.Web.Views.Components;

[HtmlTargetElement("Card")]
public class Card : RazorComponentTagHelper
{
}

Card.cshtml:

@using Sample.Web.Views.Components
@model Card
<div class="card">
  <h3>@Model.NamedSlots["title"]</h3>
  @Model.NamedSlots["content"]
</div>

You would use it like this:

<Card>
  <fragment slot="title">
    Card title
  </fragment>
  <div slot="content">
    <p>Card content</p>
    <p>Lorem ipsum</p>
  </div>
</Card>

The <fragment> element allows you to place content in a named slot without wrapping it in a container DOM element. This keeps the flow layout of your document intact.

Inspiration

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.3.3 3,039 1/25/2023
1.3.2 326 1/3/2023
1.3.1 291 12/22/2022
1.3.0 277 12/21/2022
1.2.0 330 11/16/2022
1.1.1 377 10/29/2022
1.1.0 402 10/26/2022
1.0.0 384 10/26/2022