Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
When removing an element from a List object in an On Post method, inputs using the asp-for input tag helper for the last element of the list are bound to the removed object.
Expected Behavior
I would expect the input using the asp-for tag helper to be bound to the last element of the List and never to the removed object.
Steps To Reproduce
To recreate this bug you first need a List object with at least two elements and the BindProperty attribute along with a set of inputs using the asp-for tag helper to bind the inputs to the individual elements of the List object. Then, call an On Post Handler method that removes any element from that list, other than the last. When the page reloads from the On Post Handler method, the input using the asp-for tag helper to bind the input to the last element of the list will instead be bound to the removed object.
This bugged behavior is not present if the value of the input is manually set and is also not present in any other representation of the List's data, such as when writing each element to the screen as plain text.
This is a repository of a minimalist razor page project that exhibits the bugged behavior: repo
Exceptions (if any)
No exceptions are given by this issue.
.NET Version
8.0.204
Anything else?
ASP.NET Core Version - 8.0.4
IDE - Visual Studio Enterprise 2022, 17.9.6
.NET SDK:
Version: 8.0.204
Commit: c338c7548c
Workload version: 8.0.200-manifests.7d36c14f
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.204\
.NET workloads installed:
There are no installed workloads to display.
Host:
Version: 8.0.4
Architecture: x64
Commit: 2d7eea2529
.NET SDKs installed:
8.0.204 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables:
Not set
global.json file:
Not found