Getting this exception after clicking the save button on a row edit. Everything else works fine.
Unhandled exception rendering component: Value cannot be null. (Parameter 'source')
System.ArgumentNullException: Value cannot be null. (Parameter 'source')
at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Linq.Enumerable.Where[TSource](IEnumerable1 source, Func
2 predicate)
at Radzen.Blazor.RadzenDataGridRow`1.FindComponent(String name)
at Radzen.Blazor.ValidatorBase.ValidateField(Object sender, FieldChangedEventArgs args)
at Microsoft.AspNetCore.Components.Forms.EditContext.NotifyFieldChanged(FieldIdentifier& fieldIdentifier)
at Radzen.Blazor.RadzenTextBox.OnChange(ChangeEventArgs args)
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)
fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
Unhandled exception in circuit 'Jct-lE32zXC570pYsDg1zKWyjiON6Q5sDidqPXn0Knk'.
@page "/Platforms"
@using TpsPortalWeb.Data.Models
@using TpsPortalWeb.Data.Services
@inject IPlatformService PlatformService
@inject NotificationService NotificationService
@inject DialogService DialogService
<RadzenFieldset>
<HeaderTemplate>
<h3><RadzenIcon Icon="dns" /> Platforms</h3>
</HeaderTemplate>
<ChildContent>
<RadzenDataGrid @ref="platformGrid" AllowFiltering="true" AllowColumnResize="true" FilterMode="FilterMode.Simple" PageSize="25" AllowPaging="true" AllowSorting="true" Data="@Platforms" TItem="Platform" LogicalFilterOperator="LogicalFilterOperator.Or" EditMode="DataGridEditMode.Single">
<Columns>
<RadzenDataGridColumn TItem="Platform" Property="PlatformId" Filterable="false" Title="ID" Frozen="true" TextAlign="TextAlign.Center" Width="100px" />
<RadzenDataGridColumn TItem="Platform" Property="Name" Title="Name">
<EditTemplate Context="platform">
<RadzenTextBox @bind-Value="platform.Name" Name="Name" />
<RadzenRequiredValidator Text="Name is required" Component="Name" Popup="true" />
</EditTemplate>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="Platform" Context="platform" Filterable="false" Sortable="false" TextAlign="TextAlign.Center" Width="100px">
<Template Context="platform">
<RadzenButton Icon="edit" Size="ButtonSize.Medium" Click="@(args => EditRow(platform))" @onclick:stopPropagation="true">
</RadzenButton>
</Template>
<EditTemplate Context="platform">
<RadzenButton Icon="save" Size="ButtonSize.Medium" Click="@((args) => SavePlatform(platform.PlatformId, platform.Name))">
</RadzenButton>
<RadzenButton Icon="cancel" Size="ButtonSize.Medium" ButtonStyle="ButtonStyle.Secondary" Click="@((args) => CancelChanges(platform))">
</RadzenButton>
</EditTemplate>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="Platform" Context="platform" Filterable="false" Sortable="false" TextAlign="TextAlign.Center" Width="70px">
<Template Context="platform">
<RadzenButton ButtonStyle="ButtonStyle.Danger" Icon="close" Size="ButtonSize.Medium" Click="@(args => DeletePlatform(platform.PlatformId))" @onclick:stopPropagation="true">
</RadzenButton>
</Template>
</RadzenDataGridColumn>
</Columns>
</RadzenDataGrid>
</ChildContent>
</RadzenFieldset>
<RadzenFieldset>
<HeaderTemplate>
<h3><RadzenIcon Icon="note_add" /> Create Platform</h3>
</HeaderTemplate>
<ChildContent>
<div class="row">
<label for="createName">Name: </label>
<RadzenTextBox Placeholder="Platform..." Name="Name" MaxLength="50" @bind-Value="@createName" />
<RadzenLengthValidator Component="Name" Min="3" Text="Name should be at least 3 characters" Popup=@popup Style="position: absolute" />
<RadzenButton ButtonType="ButtonType.Submit" Text="Submit" Click=@(args => CreatePlatform())></RadzenButton>
</div>
</ChildContent>
</RadzenFieldset>
@code {
RadzenDataGrid<Platform> platformGrid = new RadzenDataGrid<Platform>();
string createName = string.Empty;
List<Platform> Platforms = new List<Platform>();
bool popup;
protected override async Task OnInitializedAsync()
{
try
{
await GetPlatforms();
base.OnInitialized();
}
catch (Exception e)
{
ShowNotification(new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "Error Loading Page", Detail = e.Message, Duration = 10000 });
}
}
async Task GetPlatforms()
{
Platforms = await PlatformService.GetPlatforms();
}
async Task DeletePlatform(int PlatformId)
{
var response = await DialogService.Confirm("Are you sure you want to Delete this?", "Delete Platform?", new ConfirmOptions() { OkButtonText = "Yes", CancelButtonText = "No" }) ?? false;
if (response)
{
var result = await PlatformService.DeletePlatform(PlatformId);
ShowNotification(new NotificationMessage { Severity = NotificationSeverity.Info, Summary = "Deleting Platform Result", Detail = result, Duration = 5000 });
await GetPlatforms();
}
}
async Task CreatePlatform()
{
var result = await PlatformService.CreatePlatform(createName);
ShowNotification(new NotificationMessage { Severity = NotificationSeverity.Info, Summary = "Creating Platform Result", Detail = result, Duration = 5000 });
createName = string.Empty;
await GetPlatforms();
}
void ShowNotification(NotificationMessage message)
{
NotificationService.Notify(message);
}
void EditRow(Platform platform)
{
platformGrid.EditRow(platform);
}
async Task SavePlatform(int platFormId, string name)
{
var result = await PlatformService.UpdatePlatform(platFormId, name);
ShowNotification(new NotificationMessage { Severity = NotificationSeverity.Info, Summary = "Edit Platform Result", Detail = result, Duration = 5000 });
await GetPlatforms();
}
void CancelChanges(Platform platform)
{
platformGrid.CancelEditRow(platform);
}
}