I have a main page AreaOfLaw Component with two nested components (AlphabeticSearch and ParameterSearch) I want a parameter property value from the nested components on the main page component using a button click on the two nested components. Below are codes from the main page, AreaOfLaw.razor, then the two nested components.
I want the values of the parameter properties declared in the nested components to use a search inputs on the main form. Currently, the static property from another class is working but I don't think it's the best.
Thank you in advance.
What I have tried:
AreaOfLaw.razor:
<MudGrid Justify="Justify.Center">
<AlphabeticSearch AlphabetChanged="OnSearchAlphabet" />
<ParameterSearch ParameterChanged="OnSearchParameter" />
</MudGrid>
@code {
private void OnSearchAlphabet()
{
GetAreaOfLawByAlpahbet();
}
private void OnSearchParameter()
{
GetAreaOfLawByParameter();
}
private void GetAreaOfLawByAlpahbet()
{
if(AppProperties.AlphabeticSelection != null)
AreaOfLaws = Services.AreasOfLaw.ReadByAlphabets.Read(AppProperties.AlphabeticSelection);
}
private void GetAreaOfLawByParameter()
{
AreaOfLaws = Services.AreasOfLaw.ReadByAny.Read(AppProperties.SearchParameter);
}
}
Nested Component
AlphabeticSearch.razor
<MudItem xs="6">
<MudCard>
<MudCardContent>
<MudText>Search by starting alphabet</MudText>
<MudSelect @bind-Value="EnumValue" Label="Select an alphabet" AdornmentColor="Color.Secondary">
@foreach (Alphabets item in Enum.GetValues(typeof(Alphabets)))
{
<MudSelectItem Value="@item">@item</MudSelectItem>
}
</MudSelect>
</MudCardContent>
<MudCardActions>
<MudButton Variant="MudBlazor.Variant.Outlined" Color="Color.Secondary" OnClick="OnSearchAlphabet">Search Now</MudButton>
</MudCardActions>
</MudCard>
@code {
public enum Alphabets { A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z };
private Alphabets EnumValue { get; set; } = Alphabets.A;
[Parameter]
public EventCallback<string> AlphabetChanged { get; set; }
[Parameter]
public string? SelectedAlphabet { get; set; }
private void OnSearchAlphabet()
{
AppProperties.AlphabeticSelection = EnumValue.ToString();
AlphabetChanged.InvokeAsync(SelectedAlphabet = EnumValue.ToString());
}
}