Can't read property in code behind

@page "/weather"
@attribute [StreamRendering]

<PageTitle>Weather</PageTitle>

<h1>Weather</h1>

<p>This component demonstrates showing data.</p>

@if (Users == null)
{
<p><em>Loading...</em></p>
}
else
{
<FluentDataGrid Id="weathergrid" Items=@Users GridTemplateColumns="1fr 1fr 1fr 2fr" TGridItem=User>
<PropertyColumn Title="Date" Property="@(c => c!.UserName)" Sortable="true" Align=Align.Start/>
<PropertyColumn Title="Temp. (C)" Property="@(c => c!.FirstName)" Sortable="true" Align=Align.Center/>
<PropertyColumn Title="Temp. (F)" Property="@(c => c!.LastName)" Sortable="true" Align=Align.Center/>
<PropertyColumn Title="Summary" Property="@(c => c!.Email)" Sortable="true" Align=Align.End/>
</FluentDataGrid>
}
@page "/weather"
@attribute [StreamRendering]

<PageTitle>Weather</PageTitle>

<h1>Weather</h1>

<p>This component demonstrates showing data.</p>

@if (Users == null)
{
<p><em>Loading...</em></p>
}
else
{
<FluentDataGrid Id="weathergrid" Items=@Users GridTemplateColumns="1fr 1fr 1fr 2fr" TGridItem=User>
<PropertyColumn Title="Date" Property="@(c => c!.UserName)" Sortable="true" Align=Align.Start/>
<PropertyColumn Title="Temp. (C)" Property="@(c => c!.FirstName)" Sortable="true" Align=Align.Center/>
<PropertyColumn Title="Temp. (F)" Property="@(c => c!.LastName)" Sortable="true" Align=Align.Center/>
<PropertyColumn Title="Summary" Property="@(c => c!.Email)" Sortable="true" Align=Align.End/>
</FluentDataGrid>
}
using Microsoft.AspNetCore.Components;
using Microsoft.EntityFrameworkCore;

namespace Blazor.Web;

public partial class Weather : ComponentBase
{
public IEnumerable<User> Users { get; set; } = Enumerable.Empty<User>();

[Inject]
private IUsersRepository usersRepository { get; set; } = null!;

protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();

Users = await usersRepository.FindAll().ToListAsync();
}
}
using Microsoft.AspNetCore.Components;
using Microsoft.EntityFrameworkCore;

namespace Blazor.Web;

public partial class Weather : ComponentBase
{
public IEnumerable<User> Users { get; set; } = Enumerable.Empty<User>();

[Inject]
private IUsersRepository usersRepository { get; set; } = null!;

protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();

Users = await usersRepository.FindAll().ToListAsync();
}
}
Error
Severity Code Description Project File Line Suppression State
Error CS0103 The name 'Users' does not exist in the current context Blazor.Web C:\Users\Strypper\source\repos\LBA4\src\Presentations\Blazor.Web\Blazor.Web\Components\Pages\Weather.razor 10 Active
Severity Code Description Project File Line Suppression State
Error CS0103 The name 'Users' does not exist in the current context Blazor.Web C:\Users\Strypper\source\repos\LBA4\src\Presentations\Blazor.Web\Blazor.Web\Components\Pages\Weather.razor 10 Active
No description
1 Reply
JP
JP7mo ago
Full disclosure, I've never used Blazor/Razor pages, but, glancing at docs, what happens if you use Model.Users instead of Users?