[英]ASP.NET Core 3.1 MVC with Blazor - Missing Assembly
I'm trying to follow this tutorial about using Blazor in my existing apps with Visual Studio 2019 v16.4.3 (non-preview).我正在尝试按照本教程使用Visual Studio 2019 v16.4.3(非预览版)在我现有的应用程序中使用 Blazor 。 I first created a new Core 3.1 MVC Web App to test it out, before implementing it to my other apps.我首先创建了一个新的 Core 3.1 MVC Web App 来测试它,然后再将它实施到我的其他应用程序中。 But at the part where I need to write the <component>
tag helper in the Index.cshtml
, I keep getting this:但是在我需要在Index.cshtml
编写<component>
标签助手的部分,我不断得到这个:
The type or namespace name 'HelloWorld' could not be found (are you missing a using directive or an assembly reference?)
Here is my Index.cshtml
:这是我的Index.cshtml
:
@page
@model IndexModel
@{
ViewBag.Title = "Home Page";
}
<script src="~/_framework/blazor.server.js"></script>
<component type="typeof(HelloWorld)" render-mode="ServerPrerendered" />
and here is my HelloWorld.razor
:这是我的HelloWorld.razor
:
@page "/Hello"
<h3>HelloWorld</h3>
@code {
}
I placed the HelloWorld.razor
in a Pages
folder at the root of my solution.我将HelloWorld.razor
放在解决方案根目录下的Pages
文件夹中。 Also, if needed, here are the Startup.cs
methods that were changed:此外,如果需要,以下是已更改的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();
});
}
What am I missing?我错过了什么? Thanks!谢谢!
Apparently, the tutorial I linked in the original post is missing something.显然,我在原帖中链接的教程缺少一些东西。 Instead of:代替:
typeof(HelloWorld)
it should be something like this:它应该是这样的:
typeof(<namespace name>.<the folder the .razor file is in>.<the .razor file name>)
so in my case, it should look like this:所以在我的情况下,它应该是这样的:
typeof(TestMVCBlazor.Pages.HelloWorld)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.