繁体   English   中英

带有 Blazor 的 ASP.NET Core 3.1 MVC - 缺少程序集

[英]ASP.NET Core 3.1 MVC with Blazor - Missing Assembly

我正在尝试按照本教程使用Visual Studio 2019 v16.4.3(非预览版)在我现有的应用程序中使用 Blazor 我首先创建了一个新的 Core 3.1 MVC Web App 来测试它,然后再将它实施到我的其他应用程序中。 但是在我需要在Index.cshtml编写<component>标签助手的部分,我不断得到这个:

The type or namespace name 'HelloWorld' could not be found (are you missing a using directive or an assembly reference?)    

这是我的Index.cshtml

@page
@model IndexModel
@{
    ViewBag.Title = "Home Page";
}

<script src="~/_framework/blazor.server.js"></script>
<component type="typeof(HelloWorld)" render-mode="ServerPrerendered" />

这是我的HelloWorld.razor

@page "/Hello"

<h3>HelloWorld</h3>

@code {
}

我将HelloWorld.razor放在解决方案根目录下的Pages文件夹中。 此外,如果需要,以下是已更改的Startup.cs方法:

public void ConfigureServices(IServiceCollection services)
{
    services.AddControllersWithViews();
    services.AddRazorPages();
    services.AddServerSideBlazor();
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    ...

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

        endpoints.MapRazorPages();
        endpoints.MapBlazorHub();
    });
}

我错过了什么? 谢谢!

显然,我在原帖中链接的教程缺少一些东西。 代替:

typeof(HelloWorld)

它应该是这样的:

typeof(<namespace name>.<the folder the .razor file is in>.<the .razor file name>)

所以在我的情况下,它应该是这样的:

typeof(TestMVCBlazor.Pages.HelloWorld)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM