Aspnetcore.docs: Error CS0029 - Blazor Component

Created on 23 Mar 2020  路  2Comments  路  Source: dotnet/AspNetCore.Docs

Hi,
I've received this error.

/Users/jackptoke/Coding/BlazorApps/TokeHRM.Server/TokeHRM.Server/Pages/EmployeeOverview.razor(46,46): Error CS0029: Cannot implicitly convert type 'Microsoft.AspNetCore.Components.ElementReference' to 'TokeHRM.Server.Components.AddEmployeeDialogBase' (CS0029) (TokeHRM.Server)

I can't figure out the issue. I know that the issue at the last line of the Blazor component.

```C#

### **Here is the Blazor Component.**

```C#
@page   "/employeeoverview"
@inherits EmployeeOverviewBase


<h1 class="page-title">All Employees</h1>
@if(Employees == null)
{
    <p><em>Loading ...</em></p>
}
else
{
    <table>
        <thead>
            <tr>
                <th></th>
                <th>Employee Id</th>
                <th>First name</th>
                <th>Last name</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            @foreach(var employee in Employees)
            {
                <tr>
                    <td><img src="@($"https://gillcleerenpluralsight.blob.core.windows.net/person/{employee.EmployeeId}-small.jpg")" class="rounded-circle" /></td>
                    <td>@employee.EmployeeId</td>
                    <td>@employee.FirstName</td>
                    <td>@employee.LastName</td>
                    <td>
                        <a href="@($"employeedetail/{employee.EmployeeId}")" class="btn btn-primary table-btn">
                            <i class="fas fa-info-circle"></i>Detail
                        </a>
                        <a href="@($"employeeedit/{employee.EmployeeId}")" class="btn btn-primary table-btn">
                            <i class="fas fa-edit"></i>Edit
                        </a>
                    </td>
                </tr>
            }
        </tbody>
    </table>
}

<button @onclick="@QuickAddEmployee" class="bn btn-dark table-btn quick-add-btn">&nbsp;&nbsp;+&nbsp;&nbsp;</button>
<AddEmployeeDialog @ref="AddEmployeeDialog" ></AddEmployeeDialog>

Then here is the it's base class.**

``` C#

using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using TokeHRM.Server.Services;
using TokeHRM.Shared;
using System.Linq;
using TokeHRM.Server.Components;

namespace TokeHRM.Server.Pages
{
public class EmployeeOverviewBase : ComponentBase
{
[Inject]
public IEmployeeDataService EmployeeDataService { get; set; }

    protected AddEmployeeDialogBase AddEmployeeDialog { get; set; }

    protected override async Task OnInitializedAsync()
    {
        Employees = (await EmployeeDataService.GetAllEmployees()).ToList();
    }

    public IEnumerable<Employee> Employees { get; set; }

    protected void QuickAddEmployee()
    {
        AddEmployeeDialog.Show();
    }

    public async void AddEmployeeDialog_OnDialogClose()
    {
        Employees = (await EmployeeDataService.GetAllEmployees()).ToList();
        StateHasChanged();
    }
}

}

```

Not Triaged

Most helpful comment

It seems to set a reference to the Components namespace in the _imports.razor file.

In _Imports.razor add: @using "Components namespace"

For example: if you created the AddEmployeeDialogBase.cs component in a folder names _Components_ under _TokeHRM.Server_ project, just add: @using TokeHRM.Server.Components in _Imports.razor .

All 2 comments

Can you create an issue from the doc page? That will connect the doc to the issue. Go to the bottom of the page and select This page .

image

It seems to set a reference to the Components namespace in the _imports.razor file.

In _Imports.razor add: @using "Components namespace"

For example: if you created the AddEmployeeDialogBase.cs component in a folder names _Components_ under _TokeHRM.Server_ project, just add: @using TokeHRM.Server.Components in _Imports.razor .

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danroth27 picture danroth27  路  3Comments

nenmyx picture nenmyx  路  3Comments

StevenTCramer picture StevenTCramer  路  3Comments

serpent5 picture serpent5  路  3Comments

davisnw picture davisnw  路  3Comments