From ae597e87bf526e43cac922253f5380aa58517193 Mon Sep 17 00:00:00 2001
From: guardrex <1622880+guardrex@users.noreply.github.com>
Date: Mon, 19 Jul 2021 09:49:00 -0500
Subject: [PATCH 1/5] Binding select multiple
---
aspnetcore/blazor/components/data-binding.md | 86 +++++++++++++++-
.../blazor/components/event-handling.md | 6 +-
aspnetcore/blazor/forms-validation.md | 99 ++++++++++++++-----
3 files changed, 163 insertions(+), 28 deletions(-)
diff --git a/aspnetcore/blazor/components/data-binding.md b/aspnetcore/blazor/components/data-binding.md
index 73437b17c98e..101c9b54a8d4 100644
--- a/aspnetcore/blazor/components/data-binding.md
+++ b/aspnetcore/blazor/components/data-binding.md
@@ -75,6 +75,90 @@ Razor attribute binding is case sensitive:
* `@bind` and `@bind:event` are valid.
* `@Bind`/`@Bind:Event` (capital letters `B` and `E`) or `@BIND`/`@BIND:EVENT` (all capital letters) **are invalid**.
+::: moniker range=">= aspnetcore-6.0"
+
+## Multiple option selection with `` elements
+
+Binding supports [`multiple`](https://developer.mozilla.org/docs/Web/HTML/Attributes/multiple) option selection with `` elements. The [`@onchange`](xref:mvc/views/razor#onevent) event provides an array of the selected elements via [event arguments (`ChangeEventArgs`)](xref:blazor/components/event-handling#event-arguments). The value must be bound to an array type.
+
+`Pages/BindMultipleInput.razor`:
+
+```razor
+@page "/bind-multiple-input"
+
+
Bind Multiple inputExample
+
+
+
+
+
+
+ Selected Cars: @string.Join(", ", SelectedCars)
+
+
+
+
+
+
+
+ Selected Cities: @string.Join(", ", SelectedCities)
+
+
+@code {
+ public string[] SelectedCars { get; set; } = new string[] { };
+ public string[] SelectedCities { get; set; } = new[] { "\"sf\"", "\"sea\"" };
+
+ void SelectedCarsChanged(ChangeEventArgs e)
+ {
+ SelectedCars = (string[])e.Value;
+ }
+}
+```
+
+For information on how empty strings and `null` values are handled in data binding, see the [Binding `