Skip to content

Commit 15a0626

Browse files
committed
Add mvc sample
1 parent fa864e0 commit 15a0626

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 (467)
1+
# Samples for ASP.NET Core 6.0 (468)
22

3-
Samples for ASP.NET Core **8.0 Preview 3** is available [here](/projects/.net8) (5).
3+
Samples for ASP.NET Core **8.0 Preview 3** is available [here](/projects/.net8) (6).
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 (5)
1+
# ASP.NET 8.0 Preview 3 (6)
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

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

2222
* [RazorComponentFour](RazorComponentFour)
2323

24-
This sample demonstrates rendering a Razor Component using `Html.RenderComponentAsync` and passing data via anonymous object.
24+
This sample demonstrates rendering a Razor Component using `Html.RenderComponentAsync` and passing data via anonymous object.
25+
26+
* [RazorComponentFive](RazorComponentFive)
27+
28+
This sample demonstrates rendering a Razor Component from a MVC Controller via `RazorComponentResult` and passing data via a dictionary.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@layout RazorComponentFive.Shared.MainLayout
2+
3+
<h1>@Message</h1>
4+
@Date
5+
6+
@code{
7+
8+
[Parameter]
9+
public string Message { get; set; }
10+
11+
[Parameter]
12+
public DateOnly Date { get; set; }
13+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Components.Endpoints;
3+
4+
var builder = WebApplication.CreateBuilder();
5+
builder.Services.AddRazorComponents();
6+
builder.Services.AddMvc();
7+
var app = builder.Build();
8+
9+
app.MapControllers();
10+
11+
app.Run();
12+
13+
public class HomeController : Controller
14+
{
15+
[Route("/")]
16+
public IResult Index() => new RazorComponentResult<RazorComponentFive.Pages.Greetings>(new { Message = "Hello World too", Date = DateOnly.FromDateTime(DateTime.Now) });
17+
}
18+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Rendering a razor component using RazorComponentResult
2+
3+
This sample shows how to render a razor component using `RazorComponentResult` in MVC and passing data via anonymous object.
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+
@inherits LayoutComponentBase
2+
3+
<!doctype html>
4+
<html lang="en">
5+
<head>
6+
<meta charset="utf-8">
7+
<meta name="viewport" content="width=device-width, initial-scale=1">
8+
<title>Blazor United</title>
9+
<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">
10+
</head>
11+
<body>
12+
<div class="container">
13+
@Body
14+
</div>
15+
</body>
16+
</html>

0 commit comments

Comments
 (0)