2

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.

3
  • I know it has been 2 months, have you had a chance to find an answer to this? Commented Dec 14, 2021 at 14:36
  • 1
    No, I vaguely recall seeing somewhere that there was an error with passing to grandchildren that needed to be fixed. I ended up just using Parameter and it worked well enough. Commented Dec 17, 2021 at 0:42
  • Did you finally handle it? I have the same problem, and in my case seems the DynamicComponent component (which is in between) is breaking the cascade Commented Aug 31, 2022 at 14:31

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Taking the value out of that tag still resulted in the same error, sadly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.