C# 带Blazor的ASP.NET Core 3.1 MVC-缺少程序集
我正试图遵循以下有关Visual Studio 2019 v16.4.3(非预览)的教程。我首先创建了一个新的Core 3.1 MVC Web应用程序进行测试,然后将其应用到我的其他应用程序中。但是在我需要在C# 带Blazor的ASP.NET Core 3.1 MVC-缺少程序集,c#,asp.net-mvc,asp.net-core,blazor,blazor-server-side,C#,Asp.net Mvc,Asp.net Core,Blazor,Blazor Server Side,我正试图遵循以下有关Visual Studio 2019 v16.4.3(非预览)的教程。我首先创建了一个新的Core 3.1 MVC Web应用程序进行测试,然后将其应用到我的其他应用程序中。但是在我需要在Index.cshtml中编写标记帮助程序的部分,我一直得到以下信息: The type or namespace name 'HelloWorld' could not be found (are you missing a using directive or an assembly r
Index.cshtml
中编写
标记帮助程序的部分,我一直得到以下信息:
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
放在解决方案根目录下的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)
typeof(TestMVCBlazor.Pages.HelloWorld)