剃刀页面中的Blazor组件 [英] Blazor Components in Razor Pages

查看:157
本文介绍了剃刀页面中的Blazor组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个基本的剃须刀页面应用程序.我们想添加Blazor组件.通过复制04/16 Blazor Update视频中的步骤或使用Blazor文档,我们可以毫无问题地工作.但是,一旦我们将Blazor组件添加到Razor页面,我们所有的asp页面链接将不再起作用. URL在地址栏中更改,但是我们保持在同一页面上.启动文件如下:

We have a basic razor page app. We would like to add Blazor components. We have no problem getting this to work via replicating the steps in the 04/16 Blazor Update video or using the Blazor documentation. However, once we add the Blazor component to a Razor page, all of our asp-page links no longer work. The url changes in the address bar, but we remain on the same page. The startup file is as follows:

public void ConfigureServices(IServiceCollection services)
{
    services.Configure<CookiePolicyOptions>(options =>
    {
        options.CheckConsentNeeded = context => true;
    });

        services.AddRazorPages()
            .AddNewtonsoftJson();

        services.AddServerSideBlazor();
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Error");
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseStaticFiles();

        app.UseCookiePolicy();

        app.UseRouting();

        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapRazorPages();
            endpoints.MapBlazorHub();
         });
    }

如果有人可以指导我阅读有关Razor Pages和Blazor Components的多页教程,我相信我们可以弄清楚!预先感谢!

If some one can point me to a multi page tutorial with Razor Pages and Blazor Components, I’m sure we can figure this out! Thanks in advance!

blazor组件工作正常.

The blazor components works fine.

<a asp-page="./Index">Home</a><br /> 
<div id="Counter"> @(await Html.RenderComponentAsync<Counter>()) 
<script src="~/_framework/blazor.server.js">
</script> 
</div>

Microsoft文档状态-将组件集成到Razor Pages和MVC应用程序中将组件与现有Razor Pages和MVC应用程序一起使用.无需重写现有页面或视图即可使用Razor组件.呈现页面或视图时,将同时预渲染组件†. - https://docs.microsoft.com/en-us/aspnet/core/blazor/components?view=aspnetcore-3.0

The microsoft docs state - Integrate components into Razor Pages and MVC apps Use components with existing Razor Pages and MVC apps. There's no need to rewrite existing pages or views to use Razor components. When the page or view is rendered, components are prerendered† at the same time. - https://docs.microsoft.com/en-us/aspnet/core/blazor/components?view=aspnetcore-3.0

推荐答案

打开了此问题- https ://github.com/aspnet/AspNetCore/issues/9834 .事实证明,这是Blazor团队需要解决的错误.您还将希望看看 https://github.com/aspnet/AspNetCore/pull/10062 .要立即解决,请在此问题关闭时发出请求,或者等到下一个预览版本发布.

Opened this issue - https://github.com/aspnet/AspNetCore/issues/9834. Turns out, this was a bug that needed to be resolved by the Blazor team. You will also want to take a look at https://github.com/aspnet/AspNetCore/pull/10062. To resolve immediately, do a pull request when this issue is closed or wait till the next preview release.

这篇关于剃刀页面中的Blazor组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆