In a Blazor NET8 a component can't find RenderFragment and the Context

436 views Asked by At

I have created a component for Blazor with NET7 that is working. I published the full source code on GitHub. I want to use the same component in a NET8 Blazor application.

In a new page in the client project in the NET8 Blazor application, I added this code (this code is working fine with another project build with NET7)

<Autocomplete SearchMethod="GetTagLocal"
                @bind-Value="SelectedTag"
                Multiselect="_isMultiselect"
                EnableDropDown="true"
                placeholder="Search by verb..."
                ResultContainerCSS="tag-container"
                ResultItemCSS="tag-item">
    <SelectedTemplate Context="tag">
        @tag?.WordName
    </SelectedTemplate>
    <ResultTemplate Context="tag">
        <div class="tag-result-item-container">
            <div class="tag-result-item">
                <div class="tag-label">@tag?.WordName</div>
                <div class="tag-count"></div>
            </div>
        </div>
    </ResultTemplate>
</Autocomplete>

enter image description here

Now, I have those new errors:

  • The attribute names could not be inferred from bind attribute 'bind-Value'. Bind attributes should be of the form 'bind' or 'bind-value' along with their corresponding optional parameters like 'bind-value:event', 'bind:format' etc.
  • The name 'tag' does not exist in the current context

The SelectedTemplate and ResultTemplate are defined as

[Parameter] 
public RenderFragment<TValue>? SelectedTemplate { get; set; }
[Parameter] 
public RenderFragment<TItem>? ResultTemplate { get; set; }

As you can see in the XAML, I use the Context that gives the current rendering object. So, I can use it to display the WordName for example.

I don't know how to fix it.

1

There are 1 answers

0
RBee On BEST ANSWER

This is one of the cases where adding your code as image was necessary to find a solution. By seeing how Visual studio(VS) colours your Autocomplete component we can see that it's not being recognized as a component. In the default theme VS will add a green colour to components, the same colour used for Classes.

If your components are not coloured as such then there is likely some VS configuration issues such as missing usings and references, which is causing the component to not be recognized as a component.

From the comments you found a fix for this by performing a dotnet clean and rebuilding the project.