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: 20 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 (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-03T07:05:13.000Z (over 2 years ago)
- Last Synced: 2025-03-09T12:47:38.643Z (4 months ago)
- Topics: aspnetcore, email, generator, razor
- Language: C#
- Size: 547 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GravySoft.Razor.StringGenerator [](https://www.nuget.org/packages/GravySoft.Razor.StringGenerator/) [](https://www.nuget.org/packages/GravySoft.Razor.StringGenerator/) [](https://travis-ci.org/halomademeapc/GravySoft.Razor.StringGenerator)
#### GravySoft.Razor.StringGenerator.AspNetCore [](https://www.nuget.org/packages/GravySoft.Razor.StringGenerator.AspNetCore/) [](https://www.nuget.org/packages/GravySoft.Razor.StringGenerator.AspNetCore/)
#### GravySoft.Razor.StringGenerator.NetFramework [](https://www.nuget.org/packages/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