【问题标题】:Blazor (Server-Side) RouteAttribute is broken in core 3.0 release?Blazor(服务器端)RouteAttribute 在核心 3.0 版本中损坏?
【发布时间】:2020-01-27 08:34:26
【问题描述】:

我从预览版 7 迁移到发布 Core 3.0 我有一个只有类组件的库 我有这个 LocationViewModel:ComponentBase 它就像一个魅力但不再是了:(

我的 ViewModel:

[Layout(typeof(LayoutComponent))]
[Route("/location")]
public class LocationViewModel : ViewModelBase<Location>
{}

我的布局:

public class LayoutComponent : LayoutComponentBase
{
    ...
    Builder.AddContent(1,Body);
    ...
}

我的 _Host.cshtml

<app>@(await Html.RenderComponentAsync<LayoutComponent>(RenderMode.ServerPrerendered))
</app>

我的 app.razor

@using SystemCore.LayoutComponents;
@using Microsoft.AspNetCore.Components.Web;
@using FacilityManagementSystem.ViewModels;

<Router 
        AppAssembly="@typeof(Startup).Assembly" <-- i tried 'App' before , still no use
        AdditionalAssemblies="new List<System.Reflection.Assembly>() { typeof(LocationViewModel).Assembly }"
        >       
    <Found Context="routeData">
        <RouteView RouteData="@routeData" DefaultLayout="@typeof(LayoutComponent)" />
    </Found>
    <NotFound>
        <LayoutView Layout="@typeof(LayoutComponent)">
            <p>Sorry, there's nothing at this address.</p>
        </LayoutView>
    </NotFound>
</Router>

发生的情况是,当我转到位置“~base/location”时,我的 LocationViewModel 没有呈现

我试过这个来检查我的视图模型是否有问题..

_Host.cshtml

<app>@(await Html.RenderComponentAsync<LocationViewModel>(RenderMode.ServerPrerendered))
</app>

它成功了!

我的假设是某些东西在不直接渲染时没有捕捉到我的视图模型 请帮忙,因为这对我来说很重要,很抱歉打扰

编辑(1):BTW浏览器控制台中没有出现错误

【问题讨论】:

    标签: asp.net-core routes blazor blazor-server-side razor-components


    【解决方案1】:

    我解决了问题! 为了使用您自己的自定义LayoutComponent,您必须从App.razor 中删除DefaultLayout=@MainLayout,否则renderer 将在每个组件上强制MainLayout,即使它的LayoutAttribute 类型不是MainLayout

    希望对你有帮助...

    【讨论】:

      猜你喜欢
      • 2021-04-14
      • 1970-01-01
      • 2022-07-20
      • 2020-01-22
      • 1970-01-01
      • 2019-11-23
      • 2013-08-24
      • 1970-01-01
      • 2021-05-28
      相关资源
      最近更新 更多