ch1seL.RazorViewRender
8.0.0
dotnet add package ch1seL.RazorViewRender --version 8.0.0
NuGet\Install-Package ch1seL.RazorViewRender -Version 8.0.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="ch1seL.RazorViewRender" Version="8.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ch1seL.RazorViewRender --version 8.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ch1seL.RazorViewRender, 8.0.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.
// Install ch1seL.RazorViewRender as a Cake Addin #addin nuget:?package=ch1seL.RazorViewRender&version=8.0.0 // Install ch1seL.RazorViewRender as a Cake Tool #tool nuget:?package=ch1seL.RazorViewRender&version=8.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ch1seL.RazorViewRenderService
Easy way to render Razor View to string. It might be use to compose mail message or other texts through Razor Views.
How to use
Installation
Nuget Package Manager Console:
Install-Package ch1seL.RazorViewRenderService
.Net CLI:
dotnet add package ch1seL.RazorViewRenderService
Sample using
Create blank ASP.NET Core Web Application MVC:
dotnet new mvc -n RazorViewRender.Sample
Install Nuget package
dotnet add package ch1seL.RazorViewRenderService
Update Startup.cs:
using ch1seL.RazorViewRender;
...
public void ConfigureServices(IServiceCollection services)
{
...
services.AddRazorViewRenderService();
}
...
Add template model class Models/FooBarModel.cs
namespace RazorViewRender.Sample.Models
{
public class FooBarModel
{
public string Foo { get; set; }
public string Bar { get; set; }
}
}
Add razor template Views/Home/FooBar.cshtml
@model RazorViewRender.Sample.Models.FooBarModel
<!DOCTYPE html>
<html>
<head>
<title>@Model.Foo</title>
</head>
<body>
<div>
@Html.Raw(Model.Bar)
</div>
</body>
</html>
Update Controllers/HomeController.cs Add RazorViewRenderService as DI Add FooBar method to compose html-string content
using ch1seL.RazorViewRender;
...
private readonly RazorViewRenderService _razorViewRenderService;
public HomeController(ILogger<HomeController> logger, RazorViewRenderService razorViewRenderService)
{
_logger = logger;
_razorViewRenderService = razorViewRenderService;
}
public async Task<IActionResult> FooBar()
{
var content = await _razorViewRenderService.RenderStringAsync("Home/FooBar",
new FooBarModel
{
Foo = "Foo",
Bar = "<b>B</b>ar"
});
return new ContentResult()
{
Content = content,
ContentType = "text/html",
StatusCode = 200
};
}
...
Run application
dotnet run
Open site https://localhost:5001/Home/FooBar
to get result
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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 is compatible. 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 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.