Generating input fields for each element in an array in Blazor WASM
I'm trying to generate an input field for each element in an array, and have the input field bind that element to the array, however, no matter how i do it, it either throws an exception or doesn't bind at all.
This is basically what I have right now
Currently, it generates the input fields, but when attempting to change values, it throws an IndexOutOfRangeException
4 Replies
I don't think you can bind to the index/array of a collection at all.
What you would need to do is directly use
@onchange
.
And to that you provide a lambda expression that modifies your original array.I've done this with
And it works
Ok but you are missing the input field and binding to a local.
This would be a solution. That lambda casting needs some cleaning up if you wanna use it in any real capacity thought.
I've solved it by just making a class purely to serve as a "reference type array" and using it instead of just the default array, not the best solution but for my use case is good enough I guess.
All it has is a private array field to store the values and an indexer which is all I need
I also made an input field component that has parameters to store the reference to that object and an index representing which value to change