From 86fed85d8b11e542770b09466ae74d0d681f970c Mon Sep 17 00:00:00 2001 From: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com> Date: Thu, 2 Dec 2021 12:52:31 -1000 Subject: [PATCH] Update model-binding.md --- aspnetcore/mvc/models/model-binding.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/aspnetcore/mvc/models/model-binding.md b/aspnetcore/mvc/models/model-binding.md index 20ae51744a..d7448bf0b7 100644 --- a/aspnetcore/mvc/models/model-binding.md +++ b/aspnetcore/mvc/models/model-binding.md @@ -342,6 +342,7 @@ For targets that are collections of simple types, model binding looks for matche [a]=1050&[b]=2000&index=a&index=b ``` + * The following format is supported only in form data: ``` @@ -966,11 +967,18 @@ For targets that are collections of simple types, model binding looks for matche ``` [a]=1050&[b]=2000&index=a&index=b ``` - > [!WARNING] - > Avoid binding a parameter or a property named `index` or `Index` if it is adjacent to a collection value. Model binding will attempt to use it as the index for the collection which might result in incorrect binding. For example, consider the following action: + + Avoid binding a parameter or a property named `index` or `Index` if it is adjacent to a collection value. Model binding attempts to use `index` as the index for the collection which might result in incorrect binding. For example, consider the following action: ```csharp public IActionResult Post(string index, List products) + ``` + + In the preceding code, the `index` query string parameter binds to the `index` method parameter and also is used to bind the product collection. Renaming the `index` parameter or using a model binding attribute to configure binding avoids this issue: + + ```csharp + public IActionResult Post(string productIndex, List products) + ``` * The following format is supported only in form data: