ASP.NET Core 3.1 MVC with Blazor - 缺少程序集
ASP.NET Core 3.1 MVC with Blazor - Missing Assembly
我正在尝试使用 Visual Studio 2019 v16.4.3(非预览版)学习有关 using Blazor in my existing apps 的教程。我首先创建了一个新的 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();
});
}
我错过了什么?谢谢!
显然,我在原始 post 中链接的教程缺少某些内容。而不是:
typeof(HelloWorld)
应该是这样的:
typeof(<namespace name>.<the folder the .razor file is in>.<the .razor file name>)
所以在我的例子中,它应该是这样的:
typeof(TestMVCBlazor.Pages.HelloWorld)
我正在尝试使用 Visual Studio 2019 v16.4.3(非预览版)学习有关 using Blazor in my existing apps 的教程。我首先创建了一个新的 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();
});
}
我错过了什么?谢谢!
显然,我在原始 post 中链接的教程缺少某些内容。而不是:
typeof(HelloWorld)
应该是这样的:
typeof(<namespace name>.<the folder the .razor file is in>.<the .razor file name>)
所以在我的例子中,它应该是这样的:
typeof(TestMVCBlazor.Pages.HelloWorld)