【问题标题】:Blazor and ASP.NET Core 3.0 MVCBlazor 和 ASP.NET Core 3.0 MVC
【发布时间】:2020-02-21 06:34:18
【问题描述】:

我使用以下指南迁移了我的网络应用项目 https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio 现在我正在尝试添加简单的 Blazor 组件,但我得到的只是一个静态 html。我错过了什么?

ConfigureServices(IServiceCollection services) 方法中我有:

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

Configure(IApplicationBuilder app, IWebHostEnvironment env) 方法中我有:

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

_layout.cshtml:

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

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

浏览器日志

【问题讨论】:

  • 你如何渲染你的组件?
  • @(await Html.RenderComponentAsync(RenderMode.ServerPrerendered))

标签: asp.net-core-mvc blazor asp.net-core-3.0


【解决方案1】:

您可能缺少正确的导入:

添加一个

 _Imports.razor

给你的项目并填写

@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

【讨论】:

  • 就是这样!谢谢!
猜你喜欢
  • 2021-05-23
  • 2020-01-13
  • 1970-01-01
  • 2023-02-23
  • 2020-08-09
  • 2020-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多