2
votes

I migrated my web app project using guidelines from https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio and now I'm trying to add simple Blazor component but only thing I'm getting is a static html. What am I missing?

In ConfigureServices(IServiceCollection services) method I have:

 services.AddRazorPages(); 
 services.AddMvc();   
 services.AddServerSideBlazor();

in Configure(IApplicationBuilder app, IWebHostEnvironment env) method I have:

       app.UseEndpoints(e =>
            {
                e.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                e.MapRazorPages();
                e.MapBlazorHub();
            });

and in _layout.cshtml:

<script src="_framework/blazor.server.js" autostart="false"></script>

<script>
  Blazor.start({
    configureSignalR: function (builder) {
      builder.configureLogging(2); // LogLevel.Information
    }
  });

Browser logs

browser logs

1
How do you render your component?Postlagerkarte
<Test>@(await Html.RenderComponentAsync<Test>(RenderMode.ServerPrerendered))</Test>user656822

1 Answers

4
votes

You probably are missing the correct imports:

Add a

 _Imports.razor

to you projects and fill it with

@using System.Net.Http
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop