【问题标题】:Hot to add buttons dynamically in Blazor热门在 Blazor 中动态添加按钮
【发布时间】:2022-09-28 20:55:31
【问题描述】:

我想在 appsettings 中存储配置的选项并添加按钮来选择选项。我正在使用 Radzen。

                    <RadzenButton  Style=\"background-color:#8341ff; border: thin;\">OPTION1</RadzenButton>
                    <RadzenButton  Style=\"background-color:wheat; border: thin;\">OPTION2</RadzenButton>
                    <RadzenButton  Style=\"background-color:wheat; border: thin;\">OPTION3</RadzenButton>
  • Blazor WASM 还是 Blazor 服务器?

标签: c# blazor radzen


【解决方案1】:

对于 Blazor WASM:

在您的组件中注入 IWebAssemblyHostEnvironment 并像这样使用:

@page "/"
@using Microsoft.AspNetCore.Components.WebAssembly.Hosting
@inject IWebAssemblyHostEnvironment Env

<PageTitle>Index</PageTitle>

@if (Env.IsDevelopment())
{
    <RadzenButton Style="background-color:#8341ff; border: thin;">LAB</RadzenButton>
}
else if (Env.IsStaging())
{
    <RadzenButton Style="background-color:wheat; border: thin;">STG</RadzenButton>
}
else if (Env.IsProduction())
{
    <RadzenButton Style="background-color:wheat; border: thin;">PROD</RadzenButton>
}

对于 Blazor 服务器:

在您的组件中注入 IWebHostEnvironment 并像这样使用:

@page "/"
@inject IWebHostEnvironment Env

<PageTitle>Index</PageTitle>

@if (Env.IsDevelopment())
{
    <RadzenButton Style="background-color:#8341ff; border: thin;">LAB</RadzenButton>
}
else if (Env.IsStaging())
{
    <RadzenButton Style="background-color:wheat; border: thin;">STG</RadzenButton>
}
else if (Env.IsProduction())
{
    <RadzenButton Style="background-color:wheat; border: thin;">PROD</RadzenButton>
}

【讨论】:

  • 抱歉@Dimitris,我不清楚这个要求。这是我的需要。我应该能够从配置文件中动态读取选项并在 UI 中显示。单击按钮后,我将实现适当的功能
猜你喜欢
  • 2012-07-15
  • 2016-05-24
  • 1970-01-01
  • 1970-01-01
  • 2018-10-07
  • 2013-10-27
  • 2011-07-27
  • 2014-10-25
  • 1970-01-01
相关资源
最近更新 更多