Q:

‘ChildContent’: member names cannot be the same as their enclosing type. What does this mean?

0

This code will help you to understand what does mean by ‘ChildContent’: member names cannot be the same as their enclosing type.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

The parameter name and component (file) name should not be the same. They must be unique. For example, in the below code snippet the component name is ChildComponent so we cannot have a parameter with the same name it will not compile

[ChildComponent.razor]

<h2>Parent Title is: @Title</h2>
<button @onclick="UpdateParentsTitle">Update Title</button>
@code {
    //the parameter name cannot be ChildComponent since component name is ChildComponent
    [Parameter] public string Title { get; set; }

    [Parameter] public EventCallback<string> TitleChanged { get; set; }

    private async Task UpdateParentsTitle()
    {
        Title = "Hello, From Child Component!";
        await TitleChanged.InvokeAsync(Title);
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now