RadzenDropDown: when using multi-select, collections bound to value are set to null on clear #1146

Closed
opened 2026-01-29 17:49:36 +00:00 by claunia · 4 comments
Owner

Originally created by @pianomanjh on GitHub (Feb 29, 2024).

Describe the bug
When using RadzenDropDown to make multiple selections bound to a collection, with AllowClear set to true, a user can click to clear all choices from the collection. This results in the bound collection property being set to null, instead of clearing the collection entries. I understand this may be by design, but, especially when using nullable annotations in a codebase, results in easy-to-miss null reference exceptions.

To Reproduce
Steps to reproduce the behavior:

public class Foo
{
    public ICollection<string> Settings { get; set; } = new List<string>();
}

var foo = new Foo() { Settings = ["Two"] };
var values = new string[] { "One", "Two", "Three" };

<RadzenDropDown Multiple="true" AllowClear="true" @bind-Value="@foo" Data="@values" />

After clicking the X in the control to clear the selections, foo.Settings is null instead of an empty collection.

Expected behavior
If the property bound to value started as a non-null collection instance, I would expect that collection to remain, but be empty.

I understand this may be breaking behavior, so, as a potential mitigation, if the property bound to value started as null, we could have that property be set to null on clear...

Additional context
If this is something the team is ok changing, let me know and I'm happy to post a PR.

Originally created by @pianomanjh on GitHub (Feb 29, 2024). **Describe the bug** When using `RadzenDropDown` to make multiple selections bound to a collection, with `AllowClear` set to true, a user can click to clear all choices from the collection. This results in the bound collection property being set to null, instead of clearing the collection entries. I understand this may be by design, but, especially when using nullable annotations in a codebase, results in easy-to-miss null reference exceptions. **To Reproduce** Steps to reproduce the behavior: ``` public class Foo { public ICollection<string> Settings { get; set; } = new List<string>(); } var foo = new Foo() { Settings = ["Two"] }; var values = new string[] { "One", "Two", "Three" }; <RadzenDropDown Multiple="true" AllowClear="true" @bind-Value="@foo" Data="@values" /> ``` After clicking the X in the control to clear the selections, `foo.Settings` is null instead of an empty collection. **Expected behavior** If the property bound to value started as a non-null collection instance, I would expect that collection to remain, but be empty. I understand this may be breaking behavior, so, as a potential mitigation, if the property bound to value started as null, we could have that property be set to null on clear... **Additional context** If this is something the team is ok changing, let me know and I'm happy to post a PR.
Author
Owner

@Riedi2070 commented on GitHub (Jul 31, 2024):

#vote up

@Riedi2070 commented on GitHub (Jul 31, 2024): #vote up
Author
Owner

@enchev commented on GitHub (Oct 17, 2024):

Blazor bindings works only null/not null expression - they will not understand if a property is collection, if you clear the collection, remove or add items. We prefer not to do that since it will be exception compared to all other two-way bindings.

@enchev commented on GitHub (Oct 17, 2024): Blazor bindings works only null/not null expression - they will not understand if a property is collection, if you clear the collection, remove or add items. We prefer not to do that since it will be exception compared to all other two-way bindings.
Author
Owner

@pianomanjh commented on GitHub (Aug 20, 2025):

#vote up

@Riedi2070 this was resolved with #2261

@pianomanjh commented on GitHub (Aug 20, 2025): > #vote up @Riedi2070 this was resolved with #2261
Author
Owner

@Riedi2070 commented on GitHub (Aug 23, 2025):

#vote up

@Riedi2070 this was resolved with #2261

Thx u very much

@Riedi2070 commented on GitHub (Aug 23, 2025): > > #vote up > > [@Riedi2070](https://github.com/Riedi2070) this was resolved with [#2261](https://github.com/radzenhq/radzen-blazor/pull/2261) Thx u very much
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#1146