Search code examples
c#.netmodel-view-controllerblazorblazor-server-side

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?


Solution

  • 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.