【发布时间】:2021-05-31 04:35:18
【问题描述】:
我在 Net 5.0 上有一个剃须刀页面项目。在这个项目中,我想同时使用 .cshtml 和 .razor 页面。 (也许随着时间迁移到 .razor)。我可以在 .cshtml 页面上成功使用 razor 组件,但无法使 .razor 页面正常工作,总是出现“找不到此页面”错误。 我关注了 Combining Razor and Blazor Pages in a Single ASP.NET Core 3 Application 和其他一些人,但仍然无法正常工作。
Startup.cs 有
services.AddServerSideBlazor();
and
endpoints.MapBlazorHub();
endpoints.MapFallbackToFile("/_Host.cshtml")
_Imports.razor 在根目录中:
@using System.Net.Http
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
Pages/App.razor
@using Microsoft.AspNetCore.Components.Routing
<Router AppAssembly="@typeof(Program).Assembly"}">
<Found Context="routeData">
<RouteView RouteData="@routeData"/>
</Found>
<NotFound>
<h1>Page not found123</h1>
<p>Sorry, but there's nothing here!</p>
</NotFound>
</Router>
页面/_Host.cshtml
@page "/blazor"
@{
Layout = "_Layout";
}
<div id="app">
@(await Html.RenderComponentAsync<App>(RenderMode.Server))
</div>
页面/共享/_Layout.cshtml
<script src="_framework/blazor.server.js"></script>
@RenderSection("Scripts", required: false)
页面本身:Pages/Test.razor
@page "/test"
@implements IDisposable
<div>test</div>
我错过了什么?
【问题讨论】:
标签: c# asp.net-core blazor razor-pages asp.net-core-5.0