【问题标题】:How can I create a List of Razor Page in Blazor如何在 Blazor 中创建 Razor 页面列表
【发布时间】:2021-12-25 01:48:23
【问题描述】:

我正在尝试创建剃须刀页面列表。
我自己解释, 在我的“Index.razor”中,我实际上有:

@page "/"
@inject IJSRuntime JSRuntime

<h1 style="text-align:center;color:red" >Hey :)</h1>
<br />
<Counter/>
<NewCounter/>
<AnotherVersion/>

谁重定向到 Counter.razor、NewCounter.razor 和 AnotherVersion.razor。

但是,就像一个字符串列表,我想创建类似的东西: 有这样的清单:

List<Page> myPage = new List<Page>{Counter, NewCounter, AnotherVersion};
@page "/"
@inject IJSRuntime JSRuntime

<h1 style="text-align:center;color:red" >Hey :)</h1>
<br />
@for(int i = 0; i < myPage.Count; i++)
{
    myPage[i];
}

【问题讨论】:

  • 我不确定您所说的“页面列表”是什么意思。您的意思是 页面链接列表吗?
  • 是的,我的英语不好,所以很难理解,但我想将页面链接存储在列表中
  • 别担心,我只是想确定我理解您的要求。

标签: c# asp.net .net razor blazor


【解决方案1】:

好的,有人发布答案并立即将其删除。

所以,答案在这里:

@page "/"
@inject IJSRuntime JSRuntime

<h1 style="text-align:center;color:@bgColor" >My Dashboard</h1>
<br />
@foreach (var component in widget)
{
    <DynamicComponent Type=@component />
}

@code {
    public System.Type[] widget =
    new[] { typeof(Counter), typeof(NewCounter), typeof(AnotherVersion) };
}

(如果他转发他的消息,我会删除我的)

【讨论】:

    猜你喜欢
    • 2021-11-11
    • 2020-03-14
    • 1970-01-01
    • 2019-09-18
    • 2020-03-02
    • 2019-03-07
    • 1970-01-01
    • 2021-09-12
    • 2023-02-24
    相关资源
    最近更新 更多