Reputation: 503
I'm a bit stumped here because I do have the parameter attribute applied. I seem to be simply following the documentation in a one to one fashion.
Error message
Unhandled exception rendering component: Object of type 'Onero.Client.Features.CourseManager.CourseModelRegister' has a property matching the name 'HighSchoolRegistrationModelId', but it does not have [ParameterAttribute] applied.
Component hierarchy
//parent
<CascadingValue Value="HighSchoolRegistrationModelId">
<CourseModelAddForm></CourseModelAddForm>
</CascadingValue>
@code {
public long HighSchoolRegistrationModelId;
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
HighSchoolRegistrationModelId = await CourseService.GetHighSchool();
}
}
//middle component
@if (add)
{
<CourseModelRegister HighSchoolRegistrationModelId="@HighSchoolRegistrationModelId">
</CourseModelRegister>
}
@code {
[CascadingParameter]
protected long HighSchoolRegistrationModelId { get; set; }
private bool add = false;
protected override async Task OnParametersSetAsync()
{
await base.OnParametersSetAsync();
}
private void ShowAddForm()
{
add = true;
}
}
//Grandchild where error occurs
@code {
[CascadingParameter]
protected long HighSchoolRegistrationModelId { get; set; }
// rest of code omitted
}
Am I missing something? Perhaps this has to do with lifecycle management? I tried using OnInitialized as well as OnParametersSet.
Upvotes: 2
Views: 3940
Reputation: 579
I am pretty I have found the issue, I had the exact same situation, and its because I was passing value to the component's parameter and it was define as a [CascadingParameter], so it created a conflict.
So on this line:
<CourseModelRegister HighSchoolRegistrationModelId="@HighSchoolRegistrationModelId"> </CourseModelRegister>
You don't need to pass HighSchoolRegistrationModelId a value, because it will be filled by the [CascadingParameter]. In your case, you might need to make sure your middle component also has a [CascadingParameter] for the value to be passed to its children.
Upvotes: 3