SchemaRender.AspNetCore 1.1.0

dotnet add package SchemaRender.AspNetCore --version 1.1.0
                    
NuGet\Install-Package SchemaRender.AspNetCore -Version 1.1.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="SchemaRender.AspNetCore" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SchemaRender.AspNetCore" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="SchemaRender.AspNetCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SchemaRender.AspNetCore --version 1.1.0
                    
#r "nuget: SchemaRender.AspNetCore, 1.1.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.
#:package SchemaRender.AspNetCore@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SchemaRender.AspNetCore&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=SchemaRender.AspNetCore&version=1.1.0
                    
Install as a Cake Tool

SchemaRender.NET

An easy way to add Schema.org structured data (JSON-LD) to your ASP.NET Core application.

NuGet NuGet Downloads License: MIT .NET

Why SchemaRender?

Adding structured data to your site improves SEO and how search engines display your content. SchemaRender makes this trivial:

  • Type-safe and intuitive - Work with C# objects instead of manually writing JSON-LD
  • Seamless integration - Add schemas directly in your page models and controllers
  • Zero boilerplate - Just add schemas to the page, SchemaRender handles the rendering
  • Production-ready - Includes 20+ common schemas, or generate custom ones with attributes
  • Optimized - Source-generated code with no reflection and direct JSON streaming

Quick Start

1. Install the package:

dotnet add package SchemaRender.AspNetCore

2. Register in Program.cs:

builder.Services.AddSchemaRender();

3. Add the tag helper to _ViewImports.cshtml:

@addTagHelper *, SchemaRender.AspNetCore

4. Render schemas in your layout's <head>:

<schema-render />

5. Add schemas in your pages:

public class RecipePage : PageModel
{
    public void OnGet([FromServices] ISchemaContext schema)
    {
        schema.Add(new RecipeSchema
        {
            Name = "Mom's Lasagna",
            CookTime = TimeSpan.FromMinutes(45),
            RecipeIngredient = ["pasta", "ricotta", "mozzarella"]
        });
    }
}

That's it! SchemaRender will automatically output the JSON-LD script tags.

Usage Patterns

Razor Pages

Inject ISchemaContext using [FromServices]:

public class ArticlePage : PageModel
{
    public void OnGet([FromServices] ISchemaContext schema)
    {
        schema.Add(new ArticleSchema
        {
            Headline = "My Article",
            DatePublished = DateTimeOffset.Now,
            Author = new PersonSchema { Name = "Jane Doe" }
        });
    }
}

MVC Controllers

Inject via controller constructor or action parameter:

public class ProductController : Controller
{
    private readonly ISchemaContext _schema;

    public ProductController(ISchemaContext schema)
    {
        _schema = schema;
    }

    public IActionResult Details(int id)
    {
        var product = GetProduct(id);
        _schema.Add(new ProductSchema
        {
            Name = product.Name,
            Description = product.Description,
            Image = new ImageObjectSchema { Url = product.ImageUrl }
        });
        return View(product);
    }
}

Razor Views

Use @inject to add schemas directly in views:

@inject ISchemaContext Schema
@model BlogPost

@{
    Schema.Add(new BlogPostingSchema
    {
        Headline = Model.Title,
        DatePublished = Model.PublishedDate,
        Author = new PersonSchema { Name = Model.AuthorName }
    });
}

<article>
    <h1>@Model.Title</h1>
    
</article>

Generate Custom Schemas

Add the generator package to create schemas for types not included in the library:

dotnet add package SchemaRender.Generator
[SchemaType("JobPosting")]
public partial class JobPostingSchema
{
    public required string Title { get; init; }
    public string? Description { get; init; }
    public DateTimeOffset? DatePosted { get; init; }
    public DateTimeOffset? ValidThrough { get; init; }

    [SchemaProperty(NestedType = "Organization")]
    public string? HiringOrganization { get; init; }

    public string? EmploymentType { get; init; }
    public string? JobLocation { get; init; }
}

The generator creates the ISchema implementation automatically, handling JSON serialization and Schema.org formatting.

Source Generator

Install the optional generator package to create custom schemas:

dotnet add package SchemaRender.Generator

Attributes

[SchemaType("TypeName")] - Marks a partial class for generation:

[SchemaType("LocalBusiness")]
public partial class LocalBusinessSchema
{
    public required string Name { get; init; }
}

[SchemaProperty(Name = "...")] - Customizes the JSON property name:

[SchemaProperty(Name = "dateCreated")]
public DateTimeOffset? CreatedAt { get; init; }

[SchemaIgnore] - Excludes a property from output:

[SchemaIgnore]
public int InternalId { get; init; }

Supported Types

The generator supports primitives (string, bool, int, double), dates (DateTime, DateTimeOffset, DateOnly, TimeSpan), collections (IReadOnlyList<T>, arrays), and nested ISchema implementations.

Built-in Schemas

The library includes 20+ ready-to-use schemas:

Article, BlogPosting, Recipe, Product, LocalBusiness, Event, FAQPage, HowTo, BreadcrumbList, Review, AggregateRating, Offer, Organization, Person, ImageObject, VideoObject, WebSite, Question, Answer, ListItem, PostalAddress, GeoCoordinates, HowToStep

See the Schema.org documentation for details on each type.

Requirements

  • .NET 8.0 or later
  • ASP.NET Core 8.0 or later

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE.txt file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 is compatible.  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. 
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.1.0 91 1/19/2026
1.0.0 90 1/17/2026