You can't pass a foreach interator to a link function or it will only have the last value.
The solution is to make a local copy in a local variable and use that.