GravySoft.Razor.StringGenerator.NetFramework 1.0.0

Install-Package GravySoft.Razor.StringGenerator.NetFramework -Version 1.0.0
dotnet add package GravySoft.Razor.StringGenerator.NetFramework --version 1.0.0
<PackageReference Include="GravySoft.Razor.StringGenerator.NetFramework" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GravySoft.Razor.StringGenerator.NetFramework --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: GravySoft.Razor.StringGenerator.NetFramework, 1.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install GravySoft.Razor.StringGenerator.NetFramework as a Cake Addin
#addin nuget:?package=GravySoft.Razor.StringGenerator.NetFramework&version=1.0.0

// Install GravySoft.Razor.StringGenerator.NetFramework as a Cake Tool
#tool nuget:?package=GravySoft.Razor.StringGenerator.NetFramework&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

GravySoft.Razor.StringGenerator NuGet Logo

Service for rendering Razor MVC views to strings. This can be used for sending emails, generating PDFs, and any number of things.

You must also install either GravySoft.Razor.StringGenerator.AspNetCore or GravySoft.Razor.StringGenerator.NetFramework.

Usage

  1. Inject an IRazorViewToStringRenderer to your class.
private IRazorViewToStringRenderer renderer;
public ExampleClass(IRazorViewToStringRenderer renderer) => this.renderer = renderer;
  1. Execute your call.
string text = await renderer.RenderViewToStringAsync("~/Views/Email.cshtml", new EmailModel
{
    FirstName = "John",
    LastName = "Doe",
    FavoriteColors = new List<string> { "Red", "Purple", "Orange" }
});

Make sure you use the full path of the view

Registering Services

The service needs to be registered in as scoped so that it has access to a request HttpContext.

Microsoft Dependency Injection (.NET Core & Standalone .NET Framework)

In Startup.ConfigureServices

services.AddScoped<IRazorViewToStringRenderer, RazorViewToStringRenderer>();
Ninject (Sitefinity)

In your NinjectModule

Bind<RazorViewToStringRenderer>().To<IRazorViewToStringRenderer>();

Changelog

1.0.0

  • Initial Release

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.0.0 272 8/21/2019