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

Can I make component parameter required when building a custom Blazor component?

$
0
0

When I try to build a Blazor component I can define parameters for it like this:

@code {   [Parameter]   public string MyString { get; set; }}

My question is can I make this parameter required so that, when component is used, the project will not build unless I provide the specified parameter? Is this something I should even be worried about? I suppose I could handle any invalid values in component initialization by maybe throwing an exception if the value is not provided like this:

protected override void OnInitialized(){    base.OnInitialized();    if (string.IsNullOrWhiteSpace(MyString)) {       // throw an exception here...    }}

but is that the right way to handle this?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



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