Hi, I have a object with a collection that I want to bind to checkboxes.
public class JasminUserAdProperties()
{
[Required]
public string Email { get; set; }
[Required]
public string Name { get; set; }
/// <summary>
/// Used for checkboxes
/// </summary>
public List<AdGroupDto> Groups { get; set; } = [];
}
And this is the form / component
@using Zeus.Shared.DTO
<TelerikWindow Width="450px" Centered="true" Visible="@(AdProperties != null)" Modal="true">
<WindowTitle>
<strong>Set Jasmin roles</strong>
</WindowTitle>
<WindowActions>
<WindowAction Name="Close" OnClick="@CancelUpdateJasminRoles"/>
</WindowActions>
<WindowContent>
<TelerikForm Model="@AdProperties" OnValidSubmit="@UpdateJasminRoles">
<FormValidation>
<DataAnnotationsValidator/>
</FormValidation>
<FormItems>
@{
<FormItem>
<Template>
<label for="selectAllCheckbox">Selected All</label>
<TelerikCheckBox Id="selectAllCheckbox"
Value="@SelectAllValue"
ValueChanged="@((bool value) => ValueChanged(value))"
Indeterminate="@SelectAllIndeterminate"/>
</Template>
</FormItem>
foreach (var group in AdProperties.Groups.OrderBy(g => g.Name))
{
<FormItem>
<Template>
<label for="@group.Id">@group.Name</label>
<TelerikCheckBox @bind-Value="@group.Selected" Id="@group.Id" Name="@group.Id"/>
</Template>
</FormItem>
}
}
</FormItems>
<FormButtons>
<TelerikButton Enabled="@CanEdit" ButtonType="ButtonType.Submit" ThemeColor="@ThemeConstants.Button.ThemeColor.Primary">Save</TelerikButton>
<TelerikButton OnClick="@CancelUpdateJasminRoles">Cancel</TelerikButton>
</FormButtons>
</TelerikForm>
</WindowContent>
</TelerikWindow>
@code {
[Parameter] public EventCallback<JasminUserAdProperties> UpdateRoles { get; set; }
[Parameter] public EventCallback CancelUpdateRoles { get; set; }
[Parameter] public JasminUserAdProperties AdProperties { get; set; }
[Parameter] public bool CanEdit { get; set; }
private bool SelectAllValue => AdProperties.Groups.All(eq => eq.Selected);
private bool SelectAllIndeterminate => AdProperties.Groups.Any(eq => eq.Selected);
private void ValueChanged(bool value)
{
AdProperties.Groups.ForEach(eq => { eq.Selected = value; });
}
private void CancelUpdateJasminRoles()
{
if (CancelUpdateRoles.HasDelegate)
{
CancelUpdateRoles.InvokeAsync();
}
}
private void UpdateJasminRoles()
{
if (UpdateRoles.HasDelegate)
{
UpdateRoles.InvokeAsync(AdProperties);
}
}
}
I am getting this error(s) in spades.
Unhandled exception rendering component: Object of type 'Telerik.Blazor.Components.TelerikCheckBox`1[[System.Boolean, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' does not have a property matching the name 'Name'.
System.InvalidOperationException: Object of type 'Telerik.Blazor.Components.TelerikCheckBox`1[[System.Boolean, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' does not have a property matching the name 'Name'.
at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.ThrowForUnknownIncomingParameterName(Type targetType, String parameterName)
at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.SetProperties(ParameterView& parameters, Object target)
at Microsoft.AspNetCore.Components.ParameterView.SetParameterProperties(Object target)
at Telerik.Blazor.Components.Common.TelerikInputBase`1[[System.Boolean, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].SetParametersAsync(ParameterView parameters)
at Telerik.Blazor.Components.TelerikCheckBox`1[[System.Boolean, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].SetParametersAsync(ParameterView parameters)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.SupplyCombinedParameters(ParameterView directAndCascadingParameters)
Have been looking at Bind to nested (navigation) properties in complex objects but its not for lists.
What am I doing wrong?