Skip to content

Commit

Permalink
Add controler and route
Browse files Browse the repository at this point in the history
  • Loading branch information
danroth27 committed Apr 16, 2023
1 parent c80fed3 commit df53023
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Controllers/MvcController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Components.Endpoints;
using Microsoft.AspNetCore.Mvc;
using Index = BlazorSSR.Pages.Index;

namespace BlazorSSR.Controllers;
public class MvcController : Controller
{
public IResult Index()
{
return new RazorComponentResult<Index>(new { Message = "Hello from MVC!" });
}
}
7 changes: 6 additions & 1 deletion Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

<PageTitle>Index</PageTitle>

<h1>Hello, world!</h1>
<h1>@Message</h1>

Welcome to your new app.

@code {
[Parameter]
public string Message { get; set; } = "Hello, world!";
}
7 changes: 7 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using BlazorSSR.Data;
using BlazorSSR.Shared;
using Microsoft.AspNetCore.Components.Endpoints;
using Index = BlazorSSR.Pages.Index;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorComponents();
builder.Services.AddControllers();
builder.Services.AddSingleton<WeatherForecastService>();

var app = builder.Build();
Expand All @@ -25,4 +28,8 @@

app.MapRazorComponents<MainLayout>();

app.MapDefaultControllerRoute();

app.Map("/route", () => new RazorComponentResult<Index>(new { Message = "Hello from route!"}));

app.Run();

0 comments on commit df53023

Please sign in to comment.