Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazor DynamicComponent Containing another component (Nested Dynamic Components)

$
0
0

I have an application which displays dynamic forms sourced from the database. Right now the heart of it is a component which contains an @if statement for each supported control. Today I saw the DynamicComponent for the first time. Great!Below is code which renders a MudBlazor TextInput. I can create parameters to render other types

Question: First I would like to eliminate the outer MudItem tag. Secondly, I don't know how to specify parameters that define other tags such as in a Radio Group.

@page "/df"@using System.Net.Http@using System.Net.Http.Json@using Microsoft.AspNetCore.Components.Forms@using Microsoft.AspNetCore.Components.Routing@using Microsoft.AspNetCore.Components.Web@using static Microsoft.AspNetCore.Components.Web.RenderMode@using Microsoft.AspNetCore.Components.Web.Virtualization@using Microsoft.JSInterop@using MudBlazor;@using Newtonsoft.Json;@using static MudBlazor.CategoryTypes;@using DataAccess;@using BlazorWithG.Services;@using BlazorWithG2024.Pages.Shared;//Will loop through list of MyQuestion creating a dynamic form<MudItem id="@MyQuestion.Key" xs="@MyQuestion.BootstrapXS.Value" sm="@MyQuestion.BootstrapSM.Value" md="@MyQuestion.BootstrapMD.Value" Style="@MyQuestion.Style"><DynamicComponent Type="@MyQuestion.selectedType" Parameters="@MyQuestion.parameters"/></MudItem> @code {    private Type? selectedType = typeof(MudTextField<string>);    private string mtext { get; set; }    private DynQuestion MyQuestion = new DynQuestion();    private string _dynCSS = "";    private Dictionary<string, object> parameters = [];    protected override void OnParametersSet()    {        MyQuestion = new DynQuestion();        MyQuestion.Key = "myId";        MyQuestion.BootstrapXS = 12;        MyQuestion.BootstrapSM = 12;        MyQuestion.BootstrapMD = 12;        MyQuestion.Style = "";        MyQuestion.Label = "Hello:";        MyQuestion.Value = "There!";        MyQuestion.selectedType = typeof(MudTextField<string>);        MyQuestion.parameters = [];        MyQuestion.parameters.Add("Label", MyQuestion.Label);        MyQuestion.parameters.Add("class", _dynCSS);        MyQuestion.parameters.Add("Value", MyQuestion.Value);        mtext = "Hello";    }}

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>