I am creating a blazor server app and i have a form where an admin can edit the roster and i use InputSelect for the admin to select from users in each role. For example i have a admin role for the admin pages, then manager, kitchen and driver. When the admin is selecting the manager InputSelect, a list of all the users under the manager role appear. I managed to get that working but whenever i then submit the form to update the roster i get a object reference null error on the IList that i use a loop to display the identity users name.
This is my UI code for the InputSelect. This does partially work it does display all the users first names under that role but then submiting the form it throughs the error:
<InputSelect @bind-Value="RosterDay.Manager1" class="form-control">
<option value="">none</option>
@foreach(var man in Managers)
{
<option value="@man.FirstName">@man.FirstName</option>
}
</InputSelect>
Here is my C# code to get the list of users under the manager, kitchen and driver role:
public IList<ApplicationUser> Managers { get; set; }
public IList<ApplicationUser> Kitchens { get; set; }
public IList<ApplicationUser> Drivers { get; set; }
protected override async Task OnInitializedAsync()
{
Managers = await UserManager.GetUsersInRoleAsync("Manager");
Kitchens = await UserManager.GetUsersInRoleAsync("Kitchen");
Drivers = await UserManager.GetUsersInRoleAsync("Driver");
using var context = DbFactory.CreateDbContext();
RosterDay ??= await context.DayOfWeek.FirstOrDefaultAsync(m => m.Id == Id);
if (RosterDay is null)
{
NavigationManager.NavigateTo("notfound");
}
}
This is the error thrown
William is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1