Skip to content

Commit fa864e0

Browse files
committed
Add a new sample for Html.RenderComponentAsync
1 parent 4764131 commit fa864e0

File tree

7 files changed

+64
-4
lines changed

7 files changed

+64
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Samples for ASP.NET Core 6.0 (466)
1+
# Samples for ASP.NET Core 6.0 (467)
22

3-
Samples for ASP.NET Core **8.0 Preview 3** is available [here](/projects/.net8) (4).
3+
Samples for ASP.NET Core **8.0 Preview 3** is available [here](/projects/.net8) (5).
44

55
Samples for ASP.NET Core **7.0** is available [here](/projects/.net7) (45).
66

projects/.net8/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ASP.NET 8.0 Preview 3 (4)
1+
# ASP.NET 8.0 Preview 3 (5)
22

33
These samples require [.NET 8.0 Preview 3](https://github.com/dotnet/aspnetcore/blob/main/docs/DailyBuilds.md). You will have to install the daily build since Preview 3 is not officially released yet.
44

@@ -17,4 +17,8 @@ These samples require [.NET 8.0 Preview 3](https://github.com/dotnet/aspnetcore/
1717

1818
* [RazorComponentThree](RazorComponentThree)
1919

20-
This samples demonstrates rendering a Razor Component from Minimal API via `RazorComponentResult` and passing data via anonymous object.
20+
This sample demonstrates rendering a Razor Component from Minimal API via `RazorComponentResult` and passing data via anonymous object.
21+
22+
* [RazorComponentFour](RazorComponentFour)
23+
24+
This sample demonstrates rendering a Razor Component using `Html.RenderComponentAsync` and passing data via anonymous object.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<h1>@Message</h1>
2+
@Date
3+
4+
@code{
5+
6+
[Parameter]
7+
public string Message { get; set; }
8+
9+
[Parameter]
10+
public DateOnly Date { get; set; }
11+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
var builder = WebApplication.CreateBuilder();
4+
builder.Services.AddMvc();
5+
builder.Services.AddRazorComponents();
6+
var app = builder.Build();
7+
8+
app.MapControllers();
9+
app.Run();
10+
11+
12+
public class HomeController : Controller
13+
{
14+
[Route("/")]
15+
public IActionResult Index()
16+
{
17+
return View();
18+
}
19+
}
20+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Rendering a Razor Component using Html.RenderComponentAsync
2+
3+
This sample shows how to render a razor component using `Html.RenderComponentAsync` and passing data using anonmyous data.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
<PropertyGroup>
3+
<TargetFramework>net8.0</TargetFramework>
4+
<ImplicitUsings>true</ImplicitUsings>
5+
</PropertyGroup>
6+
</Project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
<!doctype html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<title>Blazor United</title>
8+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-aFq/bzH65dt+w6FI2ooMVUpc+21e0SRygnTpmBvdBgSdnuTN7QbdgL+OapgHtvPp" crossorigin="anonymous">
9+
</head>
10+
<body>
11+
<div class="container">
12+
@(await Html.RenderComponentAsync<RazorComponentFour.Pages.Greetings>(RenderMode.Static,
13+
new { Message = "Hello World", Date = DateOnly.FromDateTime(DateTime.Now) }))
14+
</div>
15+
</body>
16+
</html>

0 commit comments

Comments
 (0)