badumdumdap
badumdumdap

Reputation: 19

Blazor component implemented under MVC does not get rendered

Using .NET Core with the latest release version of server side Blazor, I implemented Blazor components in an existing MVC application (thanks to Chris https://chrissainty.com/using-blazor-components-in-an-existing-mvc-application/) I can only render the Blazor component on the default page (i.e. https://localhost:5433). The Blazor components works totally fine in the default page but when I try to open the view using https://localhost:5433/home/index or any other view, the Blazor component does not get rendered.

Am I missing something here?

Upvotes: 0

Views: 509

Answers (2)

Ryan Current
Ryan Current

Reputation: 1

If you would like to use other render modes, simply add <base href="~/" /> to the <head> of your Shared/_Layout.cshtml

There is an explanation available here:

https://github.com/dotnet/aspnetcore/issues/15408

Upvotes: 0

badumdumdap
badumdumdap

Reputation: 19

I figured it out! To answer some of the questions and a reproducible example:

Create an empty MVC Core Application and follow Chrissianity's tutorial on how to implement Blazor to an existing MVC https://chrissainty.com/using-blazor-components-in-an-existing-mvc-application/

I didn't notice that I was using

@(await Html.RenderComponentAsync<CoursesList>(**RenderMode.Server**, 
     new { Courses = Model }))

rather than

@(await Html.RenderComponentAsync<CoursesList(**RenderMode.ServerPrerendered**, 
   new { Courses = Model }))

When I changed my rendermode, the pages now work.

Upvotes: 1

Related Questions