Razor.Templating.Core
1.4.0-rc.1
Kindly update the package to v1.5.0 as some critical bugs were fixed in this version.
See the version list below for details.
dotnet add package Razor.Templating.Core --version 1.4.0-rc.1
NuGet\Install-Package Razor.Templating.Core -Version 1.4.0-rc.1
<PackageReference Include="Razor.Templating.Core" Version="1.4.0-rc.1" />
paket add Razor.Templating.Core --version 1.4.0-rc.1
#r "nuget: Razor.Templating.Core, 1.4.0-rc.1"
// Install Razor.Templating.Core as a Cake Addin #addin nuget:?package=Razor.Templating.Core&version=1.4.0-rc.1&prerelease // Install Razor.Templating.Core as a Cake Tool #tool nuget:?package=Razor.Templating.Core&version=1.4.0-rc.1&prerelease
Razor Templating
Using Razor for HTML templating was never been so easy like this. Render your .cshtml files into string easily using this library.
This project makes use of Razor SDK for precompiling the views.
Supported Application Types
This library supports Console, Web Api, Mvc, Worker Service, WPF, WinForms on .NET Core 3.0, .NET Core 3.1, .NET 5
Applications
- Email Templating
- Report Generation & so on
Installing Nuget Package
This library is available as Nuget package
Using .NET CLI
dotnet add package Razor.Templating.Core
Using Package Reference .csproj
<PackageReference Include="Razor.Templating.Core" Version="1.4.0-rc.1" />
Simple Usage:
using Razor.Templating.Core;
var model = new ExampleModel()
{
PlainText = "This text is rendered from Razor Views using Razor.Templating.Core",
HtmlContent = "<em>You can use it to generate email content, report generation and so on</em>"
};
var viewData = new Dictionary<string, object>();
viewData["Value1"] = "1";
viewData["Value2"] = "2";
var html = await RazorTemplateEngine.RenderAsync("/Views/ExampleView.cshtml", model, viewData);
Before applying this code, follow this article for working implementation: https://medium.com/@soundaranbu/render-razor-view-cshtml-to-string-in-net-core-7d125f32c79
Dependency Injection [Since v1.4.0-rc.1
]
Dependencies can be injected directly into views using @inject
in .csthml file. Refer sample application here
In ASP.NET Core, add dependency like below in Startup.cs - ConfigureServices
...
services.AddTransient<ExampleService>();
//add after registering all the dependencies
services.AddRazorTemplating();
or in console or other applications, add as below
// Add dependencies to the service collection
var services = new ServiceCollection();
services.AddTransient<ExampleService>();
// Add RazorTemplating after registering all dependencies
// this is important for the razor template engine to find the injected services
services.AddRazorTemplating();
var html = await RazorTemplateEngine.RenderAsync("~/Views/ExampleViewServiceInjection.cshtml");
Razor Views in Library
Razor view files(.cshtml) can be organized in a separate shared Razor Class Libary(RCL). Sample library can be found here
Sample Applications
Please find the sample applications here
Note:
- Please ensure that the views path is always unique among all the shared template projects.
References:
Thanks to all the great articles and projects which helped to bring this library out!
- https://github.com/Andy9FromSpace/razor-renderer-core
- https://github.com/aspnet/Entropy/tree/master/samples/Mvc.RenderViewToString
- https://www.frakkingsweet.com/razor-template-rendering/
- https://github.com/veccsolutions/RenderRazorConsole
- https://emilol.com/razor-mailer/
- https://codeopinion.com/using-razor-in-a-console-application/
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. 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. |
.NET Core | netcoreapp3.0 is compatible. netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.0
-
.NETCoreApp 3.1
-
net5.0
NuGet packages (17)
Showing the top 5 NuGet packages that depend on Razor.Templating.Core:
Package | Downloads |
---|---|
Sitko.Core.App.Web
Sitko.Core is a set of libraries to help build .NET Core applications fast |
|
FenixAlliance.ACL.Dependencies
Application Component for the Alliance Business Suite. |
|
Bnsights.Core
Package Description |
|
Digizuite.Optimizely
The official integration between Digizuite DAM and Optimizely CMS. |
|
VjnFramework
Core Framework vjn |
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on Razor.Templating.Core:
Repository | Stars |
---|---|
LANCommander/LANCommander
|
|
sitkoru/Sitko.Core
Sitko.Core is a set of libraries to help build .NET Core applications fast
|
Version | Downloads | Last updated | |
---|---|---|---|
2.1.0 | 20,202 | 10/14/2024 | |
2.1.0-rc.1 | 399 | 9/12/2024 | |
2.0.0 | 278,260 | 4/18/2024 | |
2.0.0-rc.1 | 2,544 | 3/4/2024 | |
1.9.0 | 609,936 | 8/25/2023 | |
1.9.0-rc.2 | 95,560 | 2/25/2023 | |
1.9.0-rc.1 | 172,260 | 11/13/2022 | |
1.8.0 | 1,043,615 | 11/5/2022 | |
1.8.0-rc.1 | 6,822 | 9/17/2022 | |
1.7.1 | 513,696 | 7/2/2022 | |
1.7.1-rc.1 | 14,172 | 2/20/2022 | |
1.7.0 | 751,143 | 11/13/2021 | |
1.7.0-preview.1 | 2,200 | 9/26/2021 | |
1.6.1-rc.1 | 5,827 | 1/13/2022 | |
1.6.0 | 444,590 | 9/26/2021 | |
1.6.0-rc.2 | 7,527 | 5/14/2021 | |
1.6.0-rc.1 | 776 | 5/13/2021 | |
1.5.0 | 408,633 | 2/27/2021 | |
1.4.0 | 103,641 | 12/5/2020 | |
1.4.0-rc.1 | 652 | 11/19/2020 | |
1.3.0 | 8,703 | 11/17/2020 | |
1.2.1 | 34,901 | 9/21/2020 | |
1.2.0 | 3,765 | 7/11/2020 | |
1.1.2 | 2,907 | 4/13/2020 | |
1.1.0 | 919 | 4/13/2020 | |
1.0.1 | 979 | 4/3/2020 | |
1.0.0 | 1,209 | 4/3/2020 |