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

Blazor : Optional parameters for the razor component

$
0
0

I am working on a blazor application which has a MainLayout where we are rendering DynamicComponent based on a list of types which are specified by the page.Also in the parameter for the second component there is a eventcallback that will notify any value changes in the component

MainLayout.razor

@foreach (var item in BaseParameters){<DynamicComponent Type="@item" Parameters="parameters" />}@code{public List<Type> BaseParameters { get; set; } = new List<Type>(typeof(MyComponent1),typeof(MyComponent2),...);Dictionary<string, object>? parameters = new() { { "OnInputCallBack", EventCallback.Factory.Create<EventCallbackArgs>(this, GetChangedValue) } };}

Now some of my components do not want to implement "Parameters" parameter and my list of types "BaseParameters" have mix of components (some has "Parameters" and some dont).

As of now I am getting null error while rendering, is there any way that I can avoid this?


Viewing all articles
Browse latest Browse all 4035

Trending Articles



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