Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/halomakes/gravysoft.razor.stringgenerator
Render Razor Views as Strings
https://github.com/halomakes/gravysoft.razor.stringgenerator
aspnetcore email generator razor
Last synced: 6 days ago
JSON representation
Render Razor Views as Strings
- Host: GitHub
- URL: https://github.com/halomakes/gravysoft.razor.stringgenerator
- Owner: halomakes
- Created: 2019-08-21T22:36:03.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-03T07:05:13.000Z (almost 2 years ago)
- Last Synced: 2025-01-09T04:00:29.567Z (19 days ago)
- Topics: aspnetcore, email, generator, razor
- Language: C#
- Size: 547 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GravySoft.Razor.StringGenerator [![Version](https://img.shields.io/nuget/vpre/GravySoft.Razor.StringGenerator)](https://www.nuget.org/packages/GravySoft.Razor.StringGenerator/) [![Downloads](https://img.shields.io/nuget/dt/GravySoft.Razor.StringGenerator)](https://www.nuget.org/packages/GravySoft.Razor.StringGenerator/) [![Build Status](https://travis-ci.org/halomademeapc/GravySoft.Razor.StringGenerator.svg?branch=master)](https://travis-ci.org/halomademeapc/GravySoft.Razor.StringGenerator)
#### GravySoft.Razor.StringGenerator.AspNetCore [![Version](https://img.shields.io/nuget/vpre/GravySoft.Razor.StringGenerator.AspNetCore)](https://www.nuget.org/packages/GravySoft.Razor.StringGenerator.AspNetCore/) [![Downloads](https://img.shields.io/nuget/dt/GravySoft.Razor.StringGenerator.AspNetCore)](https://www.nuget.org/packages/GravySoft.Razor.StringGenerator.AspNetCore/)
#### GravySoft.Razor.StringGenerator.NetFramework [![Version](https://img.shields.io/nuget/vpre/GravySoft.Razor.StringGenerator.NetFramework)](https://www.nuget.org/packages/GravySoft.Razor.StringGenerator.NetFramework/) [![Downloads](https://img.shields.io/nuget/dt/GravySoft.Razor.StringGenerator.NetFramework)](https://www.nuget.org/packages/GravySoft.Razor.StringGenerator.NetFramework/)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.
```csharp
private IRazorViewToStringRenderer renderer;
public ExampleClass(IRazorViewToStringRenderer renderer) => this.renderer = renderer;
```2. Execute your call.
```
string text = await renderer.RenderViewToStringAsync("~/Views/Email.cshtml", new EmailModel
{
FirstName = "John",
LastName = "Doe",
FavoriteColors = new List { "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*
```csharp
services.AddScoped();
```##### Ninject (Sitefinity)
*In your NinjectModule*
```csharp
Bind().To();
```### Changelog
**1.0.0**
* Initial Release