Blazor 和 ASP.NET Core 3.0 MVC
Blazor and ASP.NET Core 3.0 MVC
我使用以下指南迁移了我的 Web 应用程序项目
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
}
});
浏览器日志
您可能缺少正确的导入:
添加一个
_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
我使用以下指南迁移了我的 Web 应用程序项目 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
}
});
浏览器日志
您可能缺少正确的导入:
添加一个
_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